class JsonPathElement

Simple JsonPath Reader/Writer Attention: This reader/writer only supports the basic parent/child syntax and is not intended to support more All existing PHP libraries for JSONPath are buggy, to not properly use object base json_decode (leading to errors) or do not support writing of elements

Methods

__construct($jsonObjectOrString = null)

Create a JsonPathElement Object

array
getElements($jsonPath)

Returns the elements matching the provided path as JsonPathElement Object to allow modifications

string|null
getJson(bool $returnEmptyAsJson = false)

Retuns the current state as JSON String

mixed
getValue($jsonPath)

Returns the FIRST value of the passed JSONPath

void
remove($jsonPath, $valueKey)

No description

replaceJsonObject($jsonObjectOrString = null)

Replace the full element

void
setValue($jsonPath, $valueKey, $newValue)

Set a JSON element value to the specified value {a: {b: 'Test'}} --> setValue('$.a', 'b', 'Test')

static 
test()

No description

Details

at line 20
__construct($jsonObjectOrString = null)

Create a JsonPathElement Object

Parameters

$jsonObjectOrString

object|string JSON String or JSON stdClass Object

at line 59
array getElements($jsonPath)

Returns the elements matching the provided path as JsonPathElement Object to allow modifications

Parameters

$jsonPath

Return Value

array

at line 108
string|null getJson(bool $returnEmptyAsJson = false)

Retuns the current state as JSON String

Parameters

bool $returnEmptyAsJson

bool By default an empty JSON input will be returned as NULL to allow simpler empty checks. If true we return an empty object "}"

Return Value

string|null

at line 40
mixed getValue($jsonPath)

Returns the FIRST value of the passed JSONPath

Parameters

$jsonPath

Return Value

mixed

at line 74
void remove($jsonPath, $valueKey)

No description

Parameters

$jsonPath
$valueKey

Return Value

void

at line 326
JsonPathElement replaceJsonObject($jsonObjectOrString = null)

Replace the full element

Parameters

$jsonObjectOrString

Return Value

JsonPathElement

at line 92
void setValue($jsonPath, $valueKey, $newValue)

Set a JSON element value to the specified value {a: {b: 'Test'}} --> setValue('$.a', 'b', 'Test')

Parameters

$jsonPath

string Path to the PARENT of the key we would like to modify

$valueKey

string Key to modify

$newValue

mixed New value

Return Value

void

at line 252
static test()

No description