JSON Pointer for Python
A Python library for identifying specific nodes in a JSON document, implementing RFC 6901. Current version: 3.1.1. Release cadence: Regular updates with active maintenance.
Warnings
- breaking Ensure correct import path to access JsonPointer class
Install
-
pip install jsonpointer
Imports
- JsonPointer
from jsonpointer import JsonPointer
Quickstart
import json
from jsonpointer import JsonPointer
# Sample JSON document
json_data = {
"store": {
"book": [
{"category": "reference",
"author": "Nigel Rees",
"title": "Sayings of the Century",
"price": 8.95
},
{"category": "fiction",
"author": "Evelyn Waugh",
"title": "Sword of Honour",
"price": 12.99
}
]
}
}
# Create a JsonPointer instance
pointer = JsonPointer('/store/book/0/author')
# Resolve the pointer to get the value
author = pointer.resolve(json_data)
print(author) # Output: Nigel Rees