jsonGetObjectCount

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, or 0 if there's no such field or its value isn't an object.

JSON

Parameters & Returns

Parameters

json String
key String

Returns

Int

Quick Summary

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, or 0 if there's no such field or its value isn't an object.

Technical Exegesis...

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.

Example

Example.bam
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)