Syntax 

JsonValues


Group 

Miscellaneous 


Description 

The ParseJson function returns a JsonValues object which is a simple wrapper for accessing the members of a JSON object or JSON array. The JsonValues object supports enumeration using For Each. Enumerating a JSON object returns each member as a JsonMember object. Enumerating a JSON array returns each array element.


  • JsonValues[.Item](Index|Name)
    Get the value by numerical Index or by member Name. This is the default property. Empty is returned if the Index/Name does not exist. Indexing a JSON object by numerical index returns a JsonMember object.

  • JsonValues.Count
    This is the number of items.

  • JsonValues.Error(Index)
    This is the string representing a parsing error (index=0 is the first error). If there is no error for the specified index then the result is "". (For example, if parsing the JSON encounters two errors then Error(0) is the first and Error(1) is the second. All other values for index return "".)

  • JsonValues.JSON
    This is the string for the original JSON text.

  • JsonValues.HasMemberNames
    This is True for a JSON object. It is False for JSON array.

  • JsonValues.MemberNames
    This is the string array of member names of the JSON object.


JSON

Type Returned by Item when HasMemberNames is True

undefined

Empty

{...}

JsonMember


JSON

Type Returned by Item when HasMemberNames is False

undefined

Empty

null

Variant (Null value)

false

Boolean

true

Boolean

number

Double

"..."

String

[...]

JsonValues (the returned JsonValues's HasMemberNames is False)

{...}

JsonValues (the returned JsonValues's HasMemberNames is True)


See Also 

JsonMember, ParseJson( )


Example

Sub Main

    Dim text As String

    text = "{""member1"":""value1""}"

    Dim json As JsonValues

    Set json = ParseJson(text)

    Debug.Print json.Count ' 1

    Debug.Print json!member1 '"value1"

    Debug.Print IsEmpty(json!member2) 'True

    Debug.Print TypeName(json(0)) '"JsonMember"

    Debug.Print IsEmpty(json(1)) 'True

End Sub