### Example usage of jsonpointer Source: https://github.com/stefankoegl/python-json-pointer/blob/master/doc/commandline.md Demonstrates how to use the jsonpointer utility to inspect JSON files and resolve JSON pointers. ```bash # inspect JSON files $ cat a.json { "a": [1, 2, 3] } $ cat b.json { "a": {"b": [1, 3, 4]}, "b": 1 } # inspect JSON pointer $ cat ptr.json "/a" # resolve JSON pointer $ jsonpointer ptr.json a.json b.json [1, 2, 3] {"b": [1, 3, 4]} ``` -------------------------------- ### Setting JSON Pointers (Copy) Source: https://github.com/stefankoegl/python-json-pointer/blob/master/doc/tutorial.md Demonstrates how to use `set_pointer` with `inplace=False` to create a modified copy of the object instead of altering the original object. ```python >>> from jsonpointer import set_pointer >>> obj = {"foo": {"anArray": [ {"prop": 44}], "another prop": {"baz": "A string" }}} >>> set_pointer(obj, '/foo/anArray/0/prop', 55, inplace=False) {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}} >>> obj {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 44}]}} ``` -------------------------------- ### Using the JsonPointer Class Source: https://github.com/stefankoegl/python-json-pointer/blob/master/doc/tutorial.md Shows how to instantiate a `JsonPointer` object with a path string and then use its `resolve` method to access the same path on different objects. ```python >>> import jsonpointer >>> pointer = jsonpointer.JsonPointer('/foo/1') >>> obj1 = {'foo': ['a', 'b', 'c']} >>> pointer.resolve(obj1) 'b' >>> obj2 = {'foo': {'0': 1, '1': 10, '2': 100}} >>> pointer.resolve(obj2) 10 ``` -------------------------------- ### jsonpointer commandline utility usage Source: https://github.com/stefankoegl/python-json-pointer/blob/master/doc/commandline.md Shows the available arguments and their descriptions for the jsonpointer commandline utility. ```bash usage: jsonpointer [-h] [--indent INDENT] [-v] POINTER FILE [FILE ...] Resolve a JSON pointer on JSON files positional arguments: POINTER File containing a JSON pointer expression FILE Files for which the pointer should be resolved optional arguments: -h, --help show this help message and exit --indent INDENT Indent output by n spaces -v, --version show program's version number and exit ``` -------------------------------- ### Setting JSON Pointers (In-place) Source: https://github.com/stefankoegl/python-json-pointer/blob/master/doc/tutorial.md Illustrates how to use the `set_pointer` function to modify a value within a Python object at a specified JSON pointer path. By default, it modifies the object in-place. ```python >>> from jsonpointer import set_pointer >>> obj = {"foo": {"anArray": [ {"prop": 44}], "another prop": {"baz": "A string" }}} >>> set_pointer(obj, '/foo/anArray/0/prop', 55) {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}} >>> obj {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}} ``` -------------------------------- ### Resolving JSON Pointers Source: https://github.com/stefankoegl/python-json-pointer/blob/master/doc/tutorial.md Demonstrates how to use the `resolve_pointer` function to access nested data within a Python object using JSON pointer strings. ```python >>> from jsonpointer import resolve_pointer >>> obj = {"foo": {"anArray": [ {"prop": 44}], "another prop": {"baz": "A string" }}} >>> resolve_pointer(obj, '') == obj True >>> resolve_pointer(obj, '/foo') == obj['foo'] True >>> resolve_pointer(obj, '/foo/another prop') == obj['foo']['another prop'] True >>> resolve_pointer(obj, '/foo/another prop/baz') == obj['foo']['another prop']['baz'] True >>> resolve_pointer(obj, '/foo/anArray/0') == obj['foo']['anArray'][0] True >>> resolve_pointer(obj, '/some/path', None) == None True ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.