json-ptr docs

json-ptr docs

json_pointer.evaluate(pointer, obj)[source]

Retrieves the attribute specified by param path from param obj.

— Example 1 —

>>> import json_pointer
>>> foo = json_pointer.evaluate('/foo', {'foo':'bar'})
>>> assert foo == 'bar'

— Example 2 —

>>> foo = json_pointer.evaluate('/foo/-', {'foo': ['bar', 'baz']})
>>> assert foo == 'baz'
Parameters:
  • pointer (str) – A string JSON pointer adhering to the IETF RFC 6901 JSON pointer standard for retrieving a specific attribute from a JSON-style dictionary.
  • obj (dict) – A dict of key/value pairs.
Returns:

The attribute specified by the path attribute, or None if it doesn’t exist.

Return type:

any

Raises:

JsonPointerException – When the specified JSON pointer path does not resolve, either because the path does not exist within the dict or an out of bounds array index is specified.

class json_pointer.JsonPointer(pointer)[source]
evaluate(obj)[source]

Evaluates the JsonPointer against param obj.

Parameters:obj (dict) – A dict of key/value pairs.
Returns:The attribute specified by the path attribute, or None if it doesn’t exist.
Return type:any
Raises:JsonPointerException – When the specified JSON pointer path does not resolve, either because the path does not exist within the dict or an out of bounds array index is specified.
move_pointer_backward()[source]

Moves the pointer back to the currently referenced attribute’s parent.

— Example —

>>> pointer = JsonPointer('/list/0')
>>> pointer.move_pointer_backward()
>>> assert str(pointer) == '/list'
Returns:The name of the child attribute, or None if the JsonPointer is currently pointing to the root of the object.
Return type:str or None
move_pointer_forward(attribute)[source]

Moves the pointer forward to a child attribute of the currently referenced object.

— Example —

>>> pointer = JsonPointer('/list')
>>> pointer.move_pointer_forward(0)
>>> assert str(pointer) == '/list/0'
Parameters:attribute (str or int) – The child attribute to move to.
exception json_pointer.JsonPointerException[source]

Class for exceptions raised within the json_pointer module.