JsonBrowser
class JsonBrowser implements IteratorAggregate
Helper class for working with JSON-encoded data
Constants
| OPT_NONEXISTENT_EXCEPTIONS |
Throw exceptions instead of using NULL for nonexistent children & siblings |
| OPT_GET_VALUE |
Get node value instead of JsonBrowser object for __get() |
| OPT_DECODE |
Treat the document definition passed to the constructor as JSON, and decode it |
| OPT_CAST |
Cast values with a non-matching type requirement, instead of throwing an exception |
| OPT_DEFAULT |
Default config options [none] |
| ERR_DECODING_ERROR |
Error decoding JSON data |
| ERR_UNKNOWN_TYPE |
Encountered an unknown type |
| ERR_UNKNOWN_CHILD |
Unknown child |
| ERR_UNKNOWN_SIBLING |
Unknown sibling |
| ERR_UNKNOWN_SELF |
Unknown self |
| ERR_INVALID_CONTAINER_TYPE |
Invalid container type |
| ERR_UNKNOWN_TARGET |
Unknown target |
| ERR_INVALID_TYPE |
The value type does not match the provided type mask |
| ERR_UNDEFINED_CAST |
Cannot cast to undefined |
| TYPE_NULL |
NULL type |
| TYPE_BOOLEAN |
Boolean type |
| TYPE_STRING |
String type |
| TYPE_NUMBER |
Number type |
| TYPE_INTEGER |
Integer type (subset of TYPE_NUMBER) |
| TYPE_ARRAY |
Array type |
| TYPE_OBJECT |
Object type |
| TYPE_UNDEFINED |
Undefined type |
| TYPE_ALL |
All defined types |
Methods
Create a new instance
Dynamically set child node values as object properties
Get the current node as a document root
Attach to an existing decoded document
Check whether a child element exists
Delete the current node value
Delete the value at a given path
Get single node annotation
Get node annotations
Get a child node
Get an iterator handle
Get the JSON source for the current node
Get the node index key (i.e. the child name within the parent node)
Get the node at a given path
Get parent node
Get the node path
Get root node
Get a sibling node
Get the document value type
Get the node value
Get the value at a given path
Test whether the document value is not of a given type
Test whether the current node is the document root
Test whether the document value is of a given type
Load document from a JSON string
Check whether the current node exists in the parent document
Set a node annotation
Set the node value
Set the value at a given path
Check whether a sibling exists
Details
at line 108
__construct(int $options = self::OPT_DEFAULT, mixed $document = null)
Create a new instance
at line 125
__get(JsonBrowser|mixed $key)
Dynamically get child nodes or values as object properties
at line 144
__set(mixed $key, mixed $value)
Dynamically set child node values as object properties
Will set the value on a child node, but will not pad sparse arrays.
at line 156
JsonBrowser
asRoot()
Get the current node as a document root
at line 195
attach(mixed $document)
Attach to an existing decoded document
at line 208
bool
childExists(mixed $key)
Check whether a child element exists
at line 220
deleteValue(bool $deleteEmpty = false)
Delete the current node value
at line 233
deleteValueAt(string $path, bool $deleteEmpty = false)
Delete the value at a given path
at line 246
mixed
getAnnotation(string $name)
Get single node annotation
at line 260
array
getAnnotations(string $name = null)
Get node annotations
at line 273
JsonBrowser
getChild(mixed $key)
Get a child node
at line 292
Iterator
getIterator()
Get an iterator handle
at line 305
string
getJSON(int $options = \JSON_PRETTY_PRINT | \JSON_UNESCAPED_SLASHES | \JSON_UNESCAPED_UNICODE)
Get the JSON source for the current node
at line 317
mixed
getKey()
Get the node index key (i.e. the child name within the parent node)
at line 330
JsonBrowser
getNodeAt(string $path)
Get the node at a given path
at line 349
JsonBrowser|null
getParent()
Get parent node
at line 369
string
getPath()
Get the node path
at line 381
JsonBrowser
getRoot()
Get root node
at line 394
JsonBrowser
getSibling(mixed $key)
Get a sibling node
at line 415
int
getType(bool $onlyOne = false)
Get the document value type
at line 438
mixed
getValue(int $asType = 0, bool $cast = null)
Get the node value
at line 464
mixed
getValueAt(string $path, int $asType = 0, bool $cast = null)
Get the value at a given path
at line 493
bool
isEqualTo(JsonBrowser|mixed $value)
Test whether the document value is equal to a given value
Comparisons considered equal: - normal strictly-typed equality (===); - loosely-typed equality (==) where both values are numeric and are not strings; - any object having the same number and value for all properties, as per the above tests.
at line 512
bool
isNotType(int $types)
Test whether the document value is not of a given type
at line 524
bool
isRoot()
Test whether the current node is the document root
at line 538
bool
isType(int $types, bool $all = false)
Test whether the document value is of a given type
at line 553
loadJSON(string $json)
Load document from a JSON string
at line 586
bool
nodeExists()
Check whether the current node exists in the parent document
at line 600
setAnnotation(string $name, mixed $value, bool $clear = false)
Set a node annotation
at line 613
setValue(mixed $value, bool $padSparseArray = false)
Set the node value
at line 627
setValueAt(string $path, mixed $value, bool $padSparseArray = false)
Set the value at a given path
at line 640
bool
siblingExists(mixed $key)
Check whether a sibling exists