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:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean - the input JSON object converted to a boolean value.
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Float - the input JSON object converted to a float value.
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Integer - the input JSON object converted to an integer value.
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.String - the input JSON object converted to a string value.
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
jsonPtrExpr :: pdk.core.String - The path
Result:
output :: pdk.net.JsonObject - Node that matches given JSON Pointer: if no match exists, will return a node for which isMissingNode returns true.
Possible exceptions
NullPointerException - throws if the jsonObject or jsonPtrExpr argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
isNumber
True if this node represents a numeric JSON value
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Array<pdk.net.JsonObject>
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
fields
Map that can be used to traverse all key/value pairs for object nodes; empty map (no contents) for other types.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Map<pdk.core.String, pdk.net.JsonObject>
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
fieldName :: pdk.core.String - Name of field to look for
Result:
output :: pdk.net.JsonObject - Value of first matching node found, if any; null if none
Possible exceptions
NullPointerException - throws if the jsonObject or fieldName argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
fieldName :: pdk.core.String - Name of field to look for
Result:
output :: pdk.core.Array<pdk.net.JsonObject>
Possible exceptions
NullPointerException - throws if the jsonObject or fieldName argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
value :: pdk.core.String - Value of field to look for
Result:
output :: pdk.net.JsonObject - first matching node found, if any; null if none
Possible exceptions
NullPointerException - throws if the jsonObject or value argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
value :: pdk.core.String - Value of field to look for
Result:
output :: pdk.core.Array<pdk.net.JsonObject>
Possible exceptions
NullPointerException - throws if the jsonObject or value argument is
NULL
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:
jsonArray :: pdk.net.JsonArray - the json array
index :: pdk.core.Integer - index
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
NullPointerException - throws if the jsonArray or index argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
fieldName :: pdk.core.String
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
NullPointerException - throws if the jsonObject or fieldName argument is
NULL
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:
jsonArray :: pdk.net.JsonArray - the json array
index :: pdk.core.Integer - index
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
NullPointerException - throws if the jsonArray or index argument is
NULL
hasNotNullIndex
Method that is similar to hasIndex
, but that will return false
for explicitly added nulls.
Arguments:
jsonArray :: pdk.net.JsonArray - the json array
index :: pdk.core.Integer - index
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
NullPointerException - throws if the jsonArray or index argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
fieldName :: pdk.core.String
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject or fieldName argument is
NULL
hasNotNull
Method that is similar to has
, but that will return false
for explicitly added nulls.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
fieldName :: pdk.core.String
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject or fieldName argument is
NULL
getType
Return the type of this node.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.String
Possible exceptions
NullPointerException - throws if the jsonObject or fieldName argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
isBoolean
Method that can be used to check if this node was created from JSON boolean value (literals "true" and "false").
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
isContainerNode
Method that returns true for container nodes: Arrays and Objects.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
isFloat
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
isInteger
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
isIntegralNumber
True if this node represents an integral (integer) numeric JSON value
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
isNull
Method that can be used to check if this node was created from JSON literal null value.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
isTextual
Method that checks whether this node represents basic JSON String value.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
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:
jsonArray :: pdk.net.JsonArray - the json array
index :: pdk.core.Integer - index
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
NullPointerException - throws if the jsonArray or index argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
fieldName :: pdk.core.String
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
NullPointerException - throws if the jsonObject or fieldName argument is
NULL
toJsonObject
Converts any variable to JSON
Arguments:
variable :: pdk.core.Any - any variable
Result:
output :: pdk.net.JsonObject
Possible exceptions
NullPointerException - throws if the variable argument is
NULL
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:
jsonOne :: pdk.net.JsonObject
jsonTwo :: pdk.net.JsonObject
Result:
output :: pdk.core.Array<pdk.net.JsonOperation>
Possible exceptions
NullPointerException - throws if the jsonOne or jsonTwo argument is
NULL
merge
Merges two JsonObjects and returns a new JsonObject that contain attribute from both objects.
Arguments:
jsonOne :: pdk.net.JsonObject
jsonTwo :: pdk.net.JsonObject
Result:
output :: pdk.net.JsonObject
Possible exceptions
NullPointerException - throws if the jsonOne or jsonTwo argument is
NULL
patch
Applies an array of patch operations to the input json object and returns a new JsonObject.
Arguments:
jsonOne :: pdk.net.JsonObject
operations :: pdk.core.Array<pdk.net.JsonOperation>
Result:
output :: pdk.net.JsonObject
Possible exceptions
NullPointerException - throws if the jsonOne or operations argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
attributeName :: pdk.core.String
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
NullPointerException - throws if the jsonObject or attributeName argument is
NULL
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:
jsonObject :: pdk.net.JsonObject - the json object
attributeName :: pdk.core.String
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
NullPointerException - throws if the jsonObject or attributeName argument is
NULL
objectToArray
Converts JsonObject to JsonArray
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.net.JsonArray
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
getAttributeNames
Gets all JSON object fields names
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
Result:
output :: pdk.core.Array<pdk.core.String>
Possible exceptions
NullPointerException - throws if the jsonObject argument is
NULL
getInteger
Gets an integer value of the JsonObject attribute.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
attributeName :: pdk.core.String
Result:
output :: pdk.core.Integer
Possible exceptions
NullPointerException - throws if the jsonObject argument or attributeName is
NULL
getIntegerArray
Gets an array of integer values of the JsonObject attribute.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
attributeName :: pdk.core.String
Result:
output :: pdk.core.Array<pdk.core.Integer>
Possible exceptions
NullPointerException - throws if the jsonObject argument or attributeName is
NULL
getFloat
Gets a float value of the JsonObject attribute.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
attributeName :: pdk.core.String
Result:
output :: pdk.core.Float
Possible exceptions
NullPointerException - throws if the jsonObject argument or attributeName is
NULL
getFloatArray
Gets an array of float values of the JsonObject attribute.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
attributeName :: pdk.core.String
Result:
output :: pdk.core.Array<pdk.core.Float>
Possible exceptions
NullPointerException - throws if the jsonObject argument or attributeName is
NULL
getBoolean
Gets a boolean value of the JsonObject attribute.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
attributeName :: pdk.core.String
Result:
output :: pdk.core.Boolean
Possible exceptions
NullPointerException - throws if the jsonObject argument or attributeName is
NULL
getBooleanArray
Gets an array of boolean values of the JsonObject attribute.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
attributeName :: pdk.core.String
Result:
output :: pdk.core.Array<pdk.core.Boolean>
Possible exceptions
NullPointerException - throws if the jsonObject argument or attributeName is
NULL
getString
Gets a string value of the JsonObject attribute.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
attributeName :: pdk.core.String
Result:
output :: pdk.core.String
Possible exceptions
NullPointerException - throws if the jsonObject argument or attributeName is
NULL
getStringArray
Gets an array of string values of the JsonObject attribute.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
attributeName :: pdk.core.String
Result:
output :: pdk.core.Array<pdk.core.String>
Possible exceptions
NullPointerException - throws if the jsonObject argument or attributeName is
NULL
getJsonObject
Gets a JsonObject value of the JsonObject attribute.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
attributeName :: pdk.core.String
Result:
output :: pdk.net.JsonObject
Possible exceptions
NullPointerException - throws if the jsonObject argument or attributeName is
NULL
getJsonArray
Gets a JsonObject value of the JsonObject attribute.
Arguments:
jsonObject :: pdk.net.JsonObject - the json object
attributeName :: pdk.core.String
Result:
output :: pdk.net.JsonArray
Possible exceptions
NullPointerException - throws if the jsonObject argument or attributeName is
NULL
getArraySize
Gets a size of the JsonArray.
Arguments:
jsonArray :: pdk.net.JsonArray - the json array
Result:
output :: pdk.core.Integer
Possible exceptions
NullPointerException - throws if the jsonArray argument is
NULL
getArrayItem
Gets an element of the JsonArray.
Arguments:
jsonArray :: pdk.net.JsonArray - the json array
index :: pdk.core.Integer
Result:
output :: pdk.net.JsonObject
Possible exceptions
NullPointerException - throws if the jsonArray or index argument is
NULL
Last updated