Category: JSON
Syntax:
jsonGetObjectCount:Int(json:String, key:String)
Int
Counts the fields of an object that's the value of a field.
Takes the JSON text and the field's name.
Returns how many fields the object has (only its own: fields of objects inside it aren't counted), or 0 if there's no such field or its value isn't an object. Use it with jsonGetObjectKey to go through fields whose names you don't know.
An empty key ("") means json itself is the object, so this also works on an object from jsonGetArrayElement or jsonReadObject.
View detailed documentation online
Local j:String = jsonBegin()
j = jsonWriteString(j, "name", "Mike")
j = jsonBeginObjectField(j, "address")
j = jsonWriteString(j, "city", "Berlin")
j = jsonWriteInt(j, "zip", 10115)
j = jsonEndObject(j)
j = jsonEnd(j)
; {"name":"Mike","address":{"city":"Berlin","zip":10115}}
For i:Int = 0 To jsonGetObjectCount(j, "address") - 1
Print jsonGetObjectKey(j, "address", i) ; city, then zip
Next
Print jsonGetObjectCount(j, "") ; 2 (name and address)
BambooBasic © 2026 Michael Denathorn