pdk.util.Json

Contains functions to operate with JSON objects

Functions


asBoolean

Will try to convert value of this node to a boolean. JSON booleans map naturally; integer numbers other than 0 map to true, and 0 maps to false and Strings 'true' and 'false' map to corresponding values.

If representation cannot be converted to a boolean value (including structured types like Objects and Arrays), default value of false will be returned; no exceptions are thrown.

Arguments:

Result:

  • output :: pdk.core.Boolean - the input JSON object converted to a boolean value.

Possible exceptions


asFloat

Method that will try to convert value of this node to a pdk.core.Float. Numbers are coerced using default rules; booleans convert to 0.0 (false) and 1.0 (true), and Strings are parsed using default language integer parsing rules.

If representation cannot be converted to a float (including structured types like Objects and Arrays), default value of 0.0 will be returned; no exceptions are thrown.

Arguments:

Result:

  • output :: pdk.core.Float - the input JSON object converted to a float value.

Possible exceptions


asInteger

Method that will try to convert value of this node to an integer. Numbers are coerced using default rules; booleans convert to 0 (false) and 1 (true), and Strings are parsed using default language integer parsing rules.

If representation cannot be converted to an int (including structured types like Objects and Arrays), default value of 0 will be returned; no exceptions are thrown.

Arguments:

Result:

  • output :: pdk.core.Integer - the input JSON object converted to an integer value.

Possible exceptions


asText

Method that will return a valid String representation of the container value, if the node is a value node (method isValueNode returns true), otherwise empty String.

Arguments:

Result:

  • output :: pdk.core.String - the input JSON object converted to a string value.

Possible exceptions


at

Method that will return a valid String representation of the container value, if the node is a value node (method isValueNode returns true), otherwise empty String.

Arguments:

Result:

Possible exceptions


canConvertToInteger

Used to check whether this node is a numeric node (isInteger would return true). Note that floating-point numbers are convertible if the integral part fits without overflow (as per standard coercion rules)

NOTE: this method does not consider possible value type conversion from JSON String into Number; so even if this method returns false, it is possible that asInteger could still succeed if node is a JSON String representing integral number, or boolean.

Arguments:

Result:

Possible exceptions


isNumber

True if this node represents a numeric JSON value

Arguments:

Result:

Possible exceptions


elements

Method for accessing all value nodes of this Node, iff this node is a JSON Array or Object node. In case of Object node, field names (keys) are not included, only values. For other types of nodes, returns empty array.

Arguments:

Result:

Possible exceptions


fields

Map that can be used to traverse all key/value pairs for object nodes; empty map (no contents) for other types.

Arguments:

Result:

Possible exceptions


findParent

Method for finding a JSON Object that contains specified field, within this node or its descendants. If no matching field is found in this node or its descendants, returns null.

Arguments:

Result:

Possible exceptions


findParents

Method for finding a JSON Object that contains specified field, within this node or its descendants. If no matching field is found in this node or its descendants, returns null.

Arguments:

Result:

Possible exceptions


findValue

Method for finding the first JSON Object field with specified name in this node or its child nodes, and returning value it has. If no matching field is found in this node or its descendants, returns null.

Note that traversal is done in document order (that is, order in which nodes are iterated if using elements)

Arguments:

Result:

Possible exceptions


findValues

Method for finding the first JSON Object field with specified name in this node or its child nodes, and returning value it has. If no matching field is found in this node or its descendants, returns null.

Note that traversal is done in document order (that is, order in which nodes are iterated if using elements)

Arguments:

Result:

Possible exceptions


getByIndex

Method for accessing value of the specified element of an array node. For other nodes, null is always returned.

For array nodes, index specifies exact location within array and allows for efficient iteration over child elements (underlying storage is guaranteed to be efficiently indexable, i.e. has random-access to elements). If index is less than 0, or equal-or-greater than getArraySize, null is returned; no exception is thrown for any index.

Arguments:

Result:

  • output :: pdk.net.JsonObject - Node that represent value of the specified element, if this node is an array and has specified element. Null otherwise.

Possible exceptions


get

Method for accessing value of the specified field of an object node. If this node is not an object (or it does not have a value for specified field name), or if there is no field with such name, null is returned.

Arguments:

Result:

  • output :: pdk.net.JsonObject - Node that represent value of the specified field, if this node is an object and has value for the specified field. Null otherwise.

Possible exceptions


hasIndex

Method that allows checking whether this node is JSON Array node and contains a value for specified index If this is the case (including case of specified indexing having null as value), returns true; otherwise returns false.

Note: array element indexes are 0-based.

Arguments:

Result:

  • output :: pdk.core.Boolean - True if this node is a JSON Object node, and has a property entry with specified name (with any value, including null value)

Possible exceptions


hasNotNullIndex

Method that is similar to hasIndex, but that will return false for explicitly added nulls.

Arguments:

Result:

  • output :: pdk.core.Boolean - True if this node is a JSON Object node, and has a property entry with specified name (with any value, not including null value)

Possible exceptions


has

Method that allows checking whether this node is JSON Object node and contains value for specified property. If this is the case (including properties with explicit null values), returns true; otherwise returns false.

Arguments:

Result:

Possible exceptions


hasNotNull

Method that is similar to has, but that will return false for explicitly added nulls.

Arguments:

Result:

Possible exceptions


getType

Return the type of this node.

Arguments:

Result:

Possible exceptions


isArray

Method that returns true if this node is an Array node, false otherwise. Note that if true is returned, isContainerNode must also return true.

Arguments:

Result:

Possible exceptions


isBinary

Method that can be used to check if this node represents binary data (Base64 encoded). Although this will be externally written as JSON String value, isTextual will return false if this method returns true.

Arguments:

Result:

Possible exceptions


isBoolean

Method that can be used to check if this node was created from JSON boolean value (literals "true" and "false").

Arguments:

Result:

Possible exceptions


isContainerNode

Method that returns true for container nodes: Arrays and Objects.

Arguments:

Result:

Possible exceptions


isFloat

Arguments:

Result:

Possible exceptions


isInteger

Arguments:

Result:

Possible exceptions


isIntegralNumber

True if this node represents an integral (integer) numeric JSON value

Arguments:

Result:

Possible exceptions


isMissingNode

Method that returns true for "virtual" nodes which represent missing entries constructed by path accessor methods when there is no actual node matching given criteria.

Arguments:

Result:

Possible exceptions


isNull

Method that can be used to check if this node was created from JSON literal null value.

Arguments:

Result:

Possible exceptions


isObject

Method that returns true if this node is an Object node, false otherwise. Note that if true is returned, isContainerNode must also return true.

Arguments:

Result:

Possible exceptions


isTextual

Method that checks whether this node represents basic JSON String value.

Arguments:

Result:

Possible exceptions


isValueNode

Method that returns true for all value nodes: ones that are not containers, and that do not represent "missing" nodes in the path. Such value nodes represent String, Number, Boolean and null values from JSON.

Arguments:

Result:

Possible exceptions


pathByIndex

Method for accessing value of the specified element of an array node. For other nodes, a "missing node" (virtual node for which isMissingNode returns true) is returned.

For array nodes, index specifies exact location within array and allows for efficient iteration over child elements (underlying storage is guaranteed to be efficiently indexable, i.e. has random-access to elements). If index is less than 0, or equal-or-greater than getArraySize, "missing node" is returned; no exception is thrown for any index.

Arguments:

Result:

  • output :: pdk.net.JsonObject - Node that represent value of the specified element, if this node is an array and has specified element; otherwise "missing node" is returned.

Possible exceptions


path

Method for accessing value of the specified element of an array node. For other nodes, a "missing node" (virtual node for which isMissingNode returns true) is returned.

For array nodes, index specifies exact location within array and allows for efficient iteration over child elements (underlying storage is guaranteed to be efficiently indexable, i.e. has random-access to elements). If index is less than 0, or equal-or-greater than getArraySize, "missing node" is returned; no exception is thrown for any index.

Arguments:

Result:

  • output :: pdk.net.JsonObject - Node that represent value of the specified element, if this node is an array and has specified element; otherwise "missing node" is returned.

Possible exceptions


toJsonObject

Converts any variable to JSON

Arguments:

  • variable :: pdk.core.Any - any variable

Result:

Possible exceptions


diff

You can find more information on the RFC 6902 page

Compares two JsonObjects and returns an array of operations that need to be applied to the first object to make it equal to the second one.

Arguments:

Result:

Possible exceptions


merge

Merges two JsonObjects and returns a new JsonObject that contain attribute from both objects.

Arguments:

Result:

Possible exceptions


patch

Applies an array of patch operations to the input json object and returns a new JsonObject.

Arguments:

Result:

Possible exceptions


hasAttribute

Method that allows checking whether this node is JSON Object node and contains value for specified property. If this is the case (including properties with explicit null values), returns true; otherwise returns false.

Arguments:

Result:

  • output :: pdk.core.Boolean - True if this node is a JSON Object node, and has a property entry with specified name (with any value, including null value)

Possible exceptions


isAttributeNotNull

Method that allows checking whether this node is JSON Object node and contains value for specified property. If this is the case (not including properties with explicit null values), returns true; otherwise returns false.

Arguments:

Result:

  • output :: pdk.core.Boolean - True if this node is a JSON Object node, and has a property entry with specified name (with any value, not including null value)

Possible exceptions


objectToArray

Converts JsonObject to JsonArray

Arguments:

Result:

Possible exceptions


getAttributeNames

Gets all JSON object fields names

Arguments:

Result:

Possible exceptions


getInteger

Gets an integer value of the JsonObject attribute.

Arguments:

Result:

Possible exceptions


getIntegerArray

Gets an array of integer values of the JsonObject attribute.

Arguments:

Result:

Possible exceptions


getFloat

Gets a float value of the JsonObject attribute.

Arguments:

Result:

Possible exceptions


getFloatArray

Gets an array of float values of the JsonObject attribute.

Arguments:

Result:

Possible exceptions


getBoolean

Gets a boolean value of the JsonObject attribute.

Arguments:

Result:

Possible exceptions


getBooleanArray

Gets an array of boolean values of the JsonObject attribute.

Arguments:

Result:

Possible exceptions


getString

Gets a string value of the JsonObject attribute.

Arguments:

Result:

Possible exceptions


getStringArray

Gets an array of string values of the JsonObject attribute.

Arguments:

Result:

Possible exceptions


getJsonObject

Gets a JsonObject value of the JsonObject attribute.

Arguments:

Result:

Possible exceptions


getJsonArray

Gets a JsonObject value of the JsonObject attribute.

Arguments:

Result:

Possible exceptions


getArraySize

Gets a size of the JsonArray.

Arguments:

Result:

Possible exceptions


getArrayItem

Gets an element of the JsonArray.

Arguments:

Result:

Possible exceptions

Last updated