Farbschema: Riviera
Sie befinden sich hier: start » en » Documentation » Microsoft Access development tools » WKL Office JSON » WKL Office JSON API reference » JNode

JNode

JNode class

Signature

Dim myJNode As JNode

Summary

A node of a JSON document: an object, an array, or a value.

Parameters

None

Remarks

JNode is the common type of every node. The concrete node is a `JElement` (JSON object), a `JArray` or a `JValue`; NodeType tells which. Declare variables As JNode when the kind does not matter, and as the concrete class to reach its own members.

The default member Item makes paths short: root("customer")("name") and root("orders")(0). Positions are 0-based everywhere, as in JPath and in MSXML node lists; object keys are case-sensitive, as in JSON itself.

Not created directly; returned by other members of the library.

MemberKindSummary
`Item`PropertyReturns a child node by key (object) or by 0-based position (array).
`Value`PropertyGets or sets the value of a value node as a Variant.
`NodeType`PropertyReturns the kind of the node.
`Name`PropertyReturns the key of the node in its parent object.
`Index`PropertyReturns the 0-based position of the node in its parent object or array.
`Parent`PropertyReturns the parent node.
`Document`PropertyReturns the document the node belongs to.
`Path`PropertyReturns the JPath of the node.
`Count`PropertyReturns the number of child nodes.
`HasChildren`PropertyTells whether the node has child nodes.
`ChildNodes`PropertyReturns all child nodes as a list.
`IsNull`PropertyTells whether the node holds the JSON value null.
`StringValue`PropertyReturns the value as text; for an object or array, its JSON text.
`ToJson`MethodReturns the node as JSON text.
`JPath`MethodReturns the first node a JPath expression finds, or Nothing: a short form of SelectSingleNode.
`SelectSingleNode`MethodReturns the first node a JPath expression finds, or Nothing.
`SelectNodes`MethodReturns all nodes a JPath expression finds.
`Exists`MethodTells whether a JPath expression finds at least one node.
`GetString`MethodReturns the value at a JPath as String, or a default.
`GetLong`MethodReturns the value at a JPath as Long, or a default.
`GetDouble`MethodReturns the value at a JPath as Double, or a default.
`GetCurrency`MethodReturns the value at a JPath as Currency (converted from the written text, rounded to four decimal places), or a default.
`GetDecimal`MethodReturns the value at a JPath as a Decimal Variant (converted from the written text, 28-29 significant digits), or a default.
`GetDate`MethodReturns the value at a JPath as Date, or a default.
`GetBoolean`MethodReturns the value at a JPath as Boolean, or a default.
`GetValue`MethodReturns the value at a JPath as Variant, or a default.
`Clone`MethodReturns an independent copy of the node and its children.
`Remove`MethodRemoves the node from its parent object or array.

Code example

Dim order As JNode
For Each order In doc.SelectNodes("$.orders[*]")
    Debug.Print order.GetLong("id"), order("total").Value
Next

Inheritance

None

Item property

Signature

Property Get Item(ByVal Index As Variant) As JNode

Summary

Returns a child node by key (object) or by 0-based position (array).

Parameters

NameTypeOptionalDefaultDescription
IndexVariantNo–A key (String) for an object, a 0-based position (Long) for an array.

Property value: `JNode` – The child node.

Remarks

A missing key raises jeNotFound, a position outside the node raises jeIndexOutOfRange; use `Exists` or SelectSingleNode to test first. An object also takes a 0-based position (its keys in document order); an array takes positions only, a key raises jeTypeMismatch. Negative positions are refused here (JPath takes them: $.lines[-1]). Calling Item on a value node raises jeInvalidOperation. A String index is always a key, also "0"; convert it with CLng for an array. Other index types are converted to Long with the rules of VBA (1.5 becomes 2).

Default member: it can be left out, as in myJNode(...) for myJNode.Item(...). Read-only.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

Value property

Signature

Property Get Value() As Variant
Property Let Value(RHS As Variant)

Summary

Gets or sets the value of a value node as a Variant.

Parameters

None

Property value: Variant – The value in its natural VBA type.

Remarks

Reading returns Long for whole numbers within the Long range, Decimal for larger whole numbers (exact up to 28 digits, enough for 19-digit identifiers), Double for numbers with a fraction or exponent and for whole numbers beyond the Decimal range, String, Boolean, or Null; a number beyond the Double range raises jeTypeMismatch. The stored text never changes (Json, Save, GetString); a Double result carries only 15-17 significant digits. Use GetCurrency or GetDecimal for amounts (see Values and limits).

Writing accepts String, the numeric types, Boolean, Date (written as ISO 8601), Null, and Empty (written as null). Reading Value of an object or array raises jeInvalidOperation; use ToJson for their text.

Read/write.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

NodeType property

Signature

Property Get NodeType() As JNodeType

Summary

Returns the kind of the node.

Parameters

None

Property value: `JNodeType` – One of the `JNodeType` constants.

Remarks

Read-only.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

Name property

Signature

Property Get Name() As String

Summary

Returns the key of the node in its parent object.

Parameters

None

Property value: String – The key; an empty string for array elements and for the root node.

Remarks

Read-only.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

Index property

Signature

Property Get Index() As Long

Summary

Returns the 0-based position of the node in its parent object or array.

Parameters

None

Property value: Long – The position; -1 for the root node.

Remarks

Read-only.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

Parent property

Signature

Property Get Parent() As JNode

Summary

Returns the parent node.

Parameters

None

Property value: `JNode` – The parent; Nothing for the root node and for a node that is not attached to a document tree.

Remarks

Read-only.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

Document property

Signature

Property Get Document() As JDoc

Summary

Returns the document the node belongs to.

Parameters

None

Property value: `JDoc` – The `JDoc` that created the node.

Remarks

Read-only.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

Path property

Signature

Property Get Path() As String

Summary

Returns the JPath of the node.

Parameters

None

Property value: String – This library's canonical path from the root in dot notation, for example $.orders[0].id; it finds the node again with SelectSingleNode. It is not the bracket form of a Normalized Path of RFC 9535 (section 2.7).

Remarks

The path can be passed to SelectSingleNode of the same document to find the node again, as long as the tree has not changed.

Read-only.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

Count property

Signature

Property Get Count() As Long

Summary

Returns the number of child nodes.

Parameters

None

Property value: Long – The number of keys (object) or elements (array); 0 for a value node.

Remarks

Read-only.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

HasChildren property

Signature

Property Get HasChildren() As Boolean

Summary

Tells whether the node has child nodes.

Parameters

None

Property value: Boolean – True when Count is greater than 0.

Remarks

Read-only.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

ChildNodes property

Signature

Property Get ChildNodes() As JNodeList

Summary

Returns all child nodes as a list.

Parameters

None

Property value: `JNodeList` – A `JNodeList` of the keys' nodes (object, in document order) or the elements (array).

Remarks

Read-only.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

IsNull property

Signature

Property Get IsNull() As Boolean

Summary

Tells whether the node holds the JSON value null.

Parameters

None

Property value: Boolean – True for a null value node.

Remarks

Read-only.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

StringValue property

Signature

Property Get StringValue() As String

Summary

Returns the value as text; for an object or array, its JSON text.

Parameters

None

Property value: String – Strings unchanged, numbers as written in the document, true/false, an empty string for null, or compact JSON for objects and arrays.

Remarks

Read-only.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

ToJson method

Signature

Function ToJson(Optional ByVal Indent As Boolean = False) As String

Summary

Returns the node as JSON text.

Parameters

NameTypeOptionalDefaultDescription
IndentBooleanYesFalseTrue for indented output with line breaks (CR LF); False for compact output.

Return value: String – The JSON text of the node and its children.

Remarks

None

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

JPath method

Signature

Function JPath(ByVal Path As String) As JNode

Summary

Returns the first node a JPath expression finds, or Nothing: a short form of SelectSingleNode.

Parameters

NameTypeOptionalDefaultDescription
PathStringNo–A JPath expression; see `SelectSingleNode`.

Return value: `JNode` – The first node found, or Nothing.

Remarks

None

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

SelectSingleNode method

Signature

Function SelectSingleNode(ByVal Path As String) As JNode

Summary

Returns the first node a JPath expression finds, or Nothing.

Parameters

NameTypeOptionalDefaultDescription
PathStringNo–A JPath expression (RFC 9535). Without $ or @, the path starts at this node.

Return value: `JNode` – The first node found in document order, or Nothing.

Remarks

JPath follows RFC 9535 (JSONPath): $, @, .name, ['name'], [n] with negative positions counting from the end, [*], .. (recursive descent), unions [a,b], slices [start:end:step], and filters [?...] with ==, !=, <, <=, >, >=, &&, ||, ! and the functions length, count, match, search, value. The Goessner form [?(@.price < 10)] works too. Extensions: a path without $ or @ starts at the current node (customer.name), - is allowed in short names ($.headers.content-type). All extensions and deviations from RFC 9535 are listed in Values and limits: JPath. An invalid expression raises jePathSyntax. Compiled expressions are cached, so evaluating the same path in a loop costs the parse once.

Code example

Dim cheap As JNode
Set cheap = doc.SelectSingleNode("$.items[?@.price < 10 && @.kind == 'A']")
If Not cheap Is Nothing Then Debug.Print cheap("name").Value

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

SelectNodes method

Signature

Function SelectNodes(ByVal Path As String) As JNodeList

Summary

Returns all nodes a JPath expression finds.

Parameters

NameTypeOptionalDefaultDescription
PathStringNo–A JPath expression; see `SelectSingleNode`.

Return value: `JNodeList` – A `JNodeList` in document order; empty when nothing is found.

Remarks

None

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

Exists method

Signature

Function Exists(ByVal Path As String) As Boolean

Summary

Tells whether a JPath expression finds at least one node.

Parameters

NameTypeOptionalDefaultDescription
PathStringNo–A JPath expression; see `SelectSingleNode`.

Return value: Boolean – True when at least one node is found.

Remarks

None

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

GetString method

Signature

Function GetString(ByVal Path As String, Optional ByVal Default As Variant) As String

Summary

Returns the value at a JPath as String, or a default.

Parameters

NameTypeOptionalDefaultDescription
PathStringNo–A JPath expression relative to this node, or absolute with $.
DefaultVariantYes–The value returned when the path finds nothing or finds null.

Return value: String – The value as String.

Remarks

All getters (GetString, GetLong, GetDouble, GetCurrency, GetDecimal, GetDate, GetBoolean, GetValue) follow the same rules, like Access' Nz():

  • Without Default, a path that finds nothing raises jeNotFound, and a JSON null raises jeTypeMismatch.
  • With Default, both return the default instead.
  • A value of the wrong type always raises jeTypeMismatch, with or without default: a silently substituted value would hide a data problem.

Numbers written as strings are read when their text without surrounding spaces is a JSON number: "42" and " 4.2 " are read; "007", "+5", ".5" and "12,5" raise jeTypeMismatch. What each getter accepts, rounds and refuses: Values and limits.

Code example

Debug.Print doc.GetString("$.customer.name")
Debug.Print doc.GetString("$.customer.fax", "none")   ' like Nz()

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

GetLong method

Signature

Function GetLong(ByVal Path As String, Optional ByVal Default As Variant) As Long

Summary

Returns the value at a JPath as Long, or a default.

Parameters

NameTypeOptionalDefaultDescription
PathStringNo–A JPath expression; see `GetString`.
DefaultVariantYes–The value returned when the path finds nothing or finds null.

Return value: Long – The value as Long.

Remarks

A number with a fraction, or a number outside -2,147,483,648 to 2,147,483,647, raises jeTypeMismatch instead of being truncated; 12.0 and 1e3 are whole numbers and are accepted. The general rules are described under `GetString`.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

GetDouble method

Signature

Function GetDouble(ByVal Path As String, Optional ByVal Default As Variant) As Double

Summary

Returns the value at a JPath as Double, or a default.

Parameters

NameTypeOptionalDefaultDescription
PathStringNo–A JPath expression; see `GetString`.
DefaultVariantYes–The value returned when the path finds nothing or finds null.

Return value: Double – The value as Double.

Remarks

Converted from the written text to the nearest Double (15-17 significant digits): 9007199254740993 reads as 9007199254740992, magnitudes below about 5E-324 read as 0. A number beyond the Double range (1e400) raises jeTypeMismatch.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

GetCurrency method

Signature

Function GetCurrency(ByVal Path As String, Optional ByVal Default As Variant) As Currency

Summary

Returns the value at a JPath as Currency (converted from the written text, rounded to four decimal places), or a default.

Parameters

NameTypeOptionalDefaultDescription
PathStringNo–A JPath expression; see `GetString`.
DefaultVariantYes–The value returned when the path finds nothing or finds null.

Return value: Currency – The value as Currency, converted from the written text without a detour through Double.

Remarks

More than four decimal places are rounded to four with banker's rounding, as CCur does; a magnitude below 1E-28 becomes 0. A number outside the Currency range raises jeTypeMismatch.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

GetDecimal method

Signature

Function GetDecimal(ByVal Path As String, Optional ByVal Default As Variant) As Variant

Summary

Returns the value at a JPath as a Decimal Variant (converted from the written text, 28-29 significant digits), or a default.

Parameters

NameTypeOptionalDefaultDescription
PathStringNo–A JPath expression; see `GetString`.
DefaultVariantYes–The value returned when the path finds nothing or finds null.

Return value: Variant – The value as Variant of subtype Decimal (up to 28 significant digits).

Remarks

None

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

GetDate method

Signature

Function GetDate(ByVal Path As String, Optional ByVal Default As Variant) As Date

Summary

Returns the value at a JPath as Date, or a default.

Parameters

NameTypeOptionalDefaultDescription
PathStringNo–A JPath expression; see `GetString`.
DefaultVariantYes–The value returned when the path finds nothing or finds null.

Return value: Date – The date read from an ISO 8601 string.

Remarks

JSON has no date type; dates are ISO 8601 strings such as 2026-09-25, 2026-09-25T14:30:00Z or 2026-09-25T14:30:00+02:00. A time with a zone is converted as the document's `DateZone` says. A non-string value (for example a Unix timestamp), a string that is not ISO 8601, or a date before 1 January 100 raises jeTypeMismatch. Leading and trailing spaces are ignored; T, t or a space separate date and time; Z or z mean UTC.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

GetBoolean method

Signature

Function GetBoolean(ByVal Path As String, Optional ByVal Default As Variant) As Boolean

Summary

Returns the value at a JPath as Boolean, or a default.

Parameters

NameTypeOptionalDefaultDescription
PathStringNo–A JPath expression; see `GetString`.
DefaultVariantYes–The value returned when the path finds nothing or finds null.

Return value: Boolean – The value as Boolean.

Remarks

Accepted are JSON true and false, the strings "true" and "false" in any case, and numbers: a number that is 0 after the conversion to Decimal is False - this includes numbers below 1E-28 such as 1e-30, unlike CBool - and every other number, also one beyond the Decimal range, is True. Other strings raise jeTypeMismatch.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

GetValue method

Signature

Function GetValue(ByVal Path As String, Optional ByVal Default As Variant) As Variant

Summary

Returns the value at a JPath as Variant, or a default.

Parameters

NameTypeOptionalDefaultDescription
PathStringNo–A JPath expression; see `GetString`.
DefaultVariantYes–The value returned when the path finds nothing or finds null.

Return value: Variant – The value in its natural VBA type, as `Value` returns it.

Remarks

None

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

Clone method

Signature

Function Clone() As JNode

Summary

Returns an independent copy of the node and its children.

Parameters

None

Return value: `JNode` – A copy that belongs to the same document but is not attached to any parent.

Remarks

The copy can be inserted elsewhere with SetValue, Add or Insert; changes to it do not affect the original.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

Remove method

Signature

Sub Remove()

Summary

Removes the node from its parent object or array.

Parameters

None

Remarks

The node stays usable through the VBA variable as a detached node and can be inserted again. Removing the root node empties the document: Root becomes Nothing. A node without parent that is not the root of its document stays as it is.

Code example

None

Inheritance

Declared by JNode; also available on `JElement`, `JArray`, `JValue`.

en/wiki/msaccess/json/api-reference/jnode.txt · Zuletzt geändert: von Wolfgang van der Stille