JsonItem keys not getting subkeys

how do i get all keys from {“people”:{“Name”:“Fred”,“Age”:12,“Married”:false}}

Var myChild As New JSONItem var person As new JSONItem myChild.Value("Name") = "Fred" myChild.Value("Age") = 12 myChild.Value("Married") = False person.Value("people")=myChild var keys() As String Keys()=person.keys

gets just the people key how do i get the Age and other keys

is there a way to do something like isJsonItem(“people”)? so I can the get those keys if true.


thinking something like this could work

for each k as string  in Keys
  Var ti As Introspection.TypeInfo = GetTypeInfo(k)
  MsgBox (ti)

Parsing JSON is best done by iteration. When using the JSONItem class you won’t need introspection which is why I recommend it, unlike using Dictionary / ParseJSON.

You would need to build the keys array yourself. I can’t think of a good reason to have an array of every key that exists on all levels, because you can’t really make use of it.

Maybe share what you’re actually trying to parse, that will help you get a more useful answer. The JSON you’ve provided as an example contains a single object for “people” while the name suggests your real JSON contains an array. It would be much simpler for all of us (both you and those trying to help) to only have to explain things once by using your real JSON.

Thanks for the reply Tim

I don’t have a problem using the jsonitem class.
I am trying to create a routine that will allow different data to be mapped to the properties of a class.

I have a customer class with several properties FirstName LastName Address etc.
by creating a jsonItem i can map between an incoming jsonData having keys of First_Name mapped to the customer.FirstName key.

Then I can make a new jsonItem mapped to FName coming from a different data source.

So the jsonData key names will change based on the different providers.

I’m not sure if I can make the routine totally generic but that’s the goal.
It’s working well but I have to know ahead of time and code for any subKeys

I will try to post json data, but because I’m trying to support many formats not sure how helpful it will be. especially when I don’t have all the formats that I want to support yet

Hope this makes sense.

It seems like you’re possibly looking for a way to serialize classes to JSON. I can provide you an open source project where you can find a serializable class, but you’ll have to read through the code to understand how to use it.

In short, anything you want to be serializable needs to be a subclass of BKS_JSONResource.Base

That’s the dirty secret to both xml and json. You have to know the contents (expected keys) before you can actually use it. There’s nothing “generic” about either, except for the way it is formatted.

1 Like
Var data As New JSONItem(TextJSON.Text)

For Each key As String In data.Keys

Var people As JSONItem = data.Child("people")
For Each key As String In people.Keys

'Var Name As String = people.Lookup("Name","")
Var Name As String = people.Value("Name")

making progress

m=orders.child("billing_address").value("first_name") //Child(s)

works fine.

how can I make
` var s as string

m=orders.child (s)`


have a look for Extends in docu.
you could make a method for it and it would look like

I just want to pass s as string for the various child items.
there’s not an easy way to do that?

you can shorten it with


i think json did not have a query method, xml class have one.
i not saw any example in docu where you can access something like “billing_address.first_name” direct.