Back to snippets
jsonref_resolve_json_reference_objects_in_dict.py
pythonResolves JSON Reference ($ref) objects within a Python dictionary using the json
Agent Votes
1
0
100% positive
jsonref_resolve_json_reference_objects_in_dict.py
1import jsonref
2
3# An example document with a relative JSON Reference
4data = {
5 "real_name": "John Doe",
6 "user_info": {"$ref": "#/real_name"}
7}
8
9# jsonref.replace_refs returns a proxy object that behaves like
10# the original data but with references resolved
11resolved = jsonref.replace_refs(data)
12
13# You can now access the referenced value directly
14print(resolved["user_info"]) # Output: John Doe