JElement
JElement class
Signature
Dim myJElement As JElement
Summary
A JSON object: key–value pairs in document order.
Parameters
None
Remarks
Keys are case-sensitive. A duplicate key in loaded JSON keeps the last value, as most JSON parsers do.
Not created directly; returned by other members of the library.
| Member | Kind | Summary |
|---|---|---|
| `Keys` | Property | Returns all keys in document order. |
| `HasKey` | Method | Tells whether a key exists. |
| `SetValue` | Method | Sets the value of a key, new or replacing, and returns its node. |
| `AddElement` | Method | Adds a new, empty object under a key. |
| `AddArray` | Method | Adds a new, empty array under a key. |
| `RemoveKey` | Method | Removes a key and its value. |
| `Clear` | Method | Removes all keys. |
Code example
None
Inheritance
JElement inherits every member of `JNode`; inherited members are described on the base class's page.
Keys property
Signature
Property Get Keys() As Variant
Summary
Returns all keys in document order.
Parameters
None
Property value: Variant – A String array; an array without elements for an empty object.
Remarks
Read-only.
Code example
None
Inheritance
Declared by JElement.
HasKey method
Signature
Function HasKey(ByVal Key As String) As Boolean
Summary
Tells whether a key exists.
Parameters
| Name | Type | Optional | Default | Description |
|---|---|---|---|---|
Key | String | No | – | The key; case-sensitive. |
Return value: Boolean – True when the key exists.
Remarks
None
Code example
None
Inheritance
Declared by JElement.
SetValue method
Signature
Function SetValue(ByVal Key As String, ByVal Value As Variant) As JNode
Summary
Sets the value of a key, new or replacing, and returns its node.
Parameters
| Name | Type | Optional | Default | Description |
|---|---|---|---|---|
Key | String | No | – | The key. |
Value | Variant | No | – | The value (the types of `JNode.Value`), or a node to insert. |
Return value: `JNode` – The node that holds the value.
Remarks
A detached node (new, cloned, or removed) is inserted itself: later changes through the VBA variable show in the tree. A node that is already attached, or that belongs to another document, is copied. Inserting a node into its own subtree raises jeInvalidOperation.
Values that have no JSON form (objects other than nodes, arrays with more than one dimension, Scripting.Dictionary, Collection) raise jeUnsupportedValue.
Code example
root.SetValue "customer", "Miller" root.SetValue "date", Date ' written as ISO 8601 root.SetValue "note", Null
Inheritance
Declared by JElement.
AddElement method
Signature
Function AddElement(ByVal Key As String) As JElement
Summary
Adds a new, empty object under a key.
Parameters
| Name | Type | Optional | Default | Description |
|---|---|---|---|---|
Key | String | No | – | The key; an existing key is replaced. |
Return value: `JElement` – The new `JElement`.
Remarks
None
Code example
None
Inheritance
Declared by JElement.
AddArray method
Signature
Function AddArray(ByVal Key As String) As JArray
Summary
Adds a new, empty array under a key.
Parameters
| Name | Type | Optional | Default | Description |
|---|---|---|---|---|
Key | String | No | – | The key; an existing key is replaced. |
Remarks
None
Code example
None
Inheritance
Declared by JElement.
RemoveKey method
Signature
Function RemoveKey(ByVal Key As String) As Boolean
Summary
Removes a key and its value.
Parameters
| Name | Type | Optional | Default | Description |
|---|---|---|---|---|
Key | String | No | – | The key. |
Return value: Boolean – True when the key existed.
Remarks
None
Code example
None
Inheritance
Declared by JElement.
Clear method
Signature
Sub Clear()
Summary
Removes all keys.
Parameters
None
Remarks
None
Code example
None
Inheritance
Declared by JElement.