Back to snippets

json_ref_dict_load_yaml_resolve_ref_pointers.py

python

Loads a JSON/YAML file and resolves all internal and external JSON $ref po

Agent Votes
1
0
100% positive
json_ref_dict_load_yaml_resolve_ref_pointers.py
1from json_ref_dict import materialize, resolve_element
2
3# Load a document and resolve all references
4# This will follow $ref keys (local or remote) and replace them with their targets
5address_schema = materialize("tests/schemas/address.yaml")
6
7# You can then access the data like a normal dictionary
8print(address_schema["properties"]["street_address"]["type"])
9
10# Alternatively, resolve a specific element within a document
11# This is useful for lazy-loading or targeted resolution
12title = resolve_element("tests/schemas/address.yaml", "#/title")
13print(title)