53 lines
1.2 KiB
Python
53 lines
1.2 KiB
Python
#!/usr/bin/env python3
|
|
|
|
"""
|
|
JSON content replace tets
|
|
"""
|
|
|
|
from deepdiff import DeepDiff
|
|
from corelibs.debug_handling.dump_data import dump_data
|
|
from corelibs.json_handling.json_helper import modify_with_jsonpath
|
|
|
|
|
|
def main() -> None:
|
|
"""
|
|
Comment
|
|
"""
|
|
__data = {
|
|
'a': 'b',
|
|
'foobar': [1, 2, 'a'],
|
|
'bar': {
|
|
'a': 1,
|
|
'b': 'c'
|
|
},
|
|
'baz': [
|
|
{
|
|
'aa': 1,
|
|
'ab': 'cc'
|
|
},
|
|
{
|
|
'ba': 2,
|
|
'bb': 'dd'
|
|
},
|
|
],
|
|
'foo': {
|
|
'a': [1, 2, 3],
|
|
'b': ['a', 'b', 'c']
|
|
}
|
|
}
|
|
|
|
# Modify some values using JSONPath
|
|
__replace_data = modify_with_jsonpath(__data, 'bar.a', 42)
|
|
__replace_data = modify_with_jsonpath(__replace_data, 'foo.b[1]', 'modified')
|
|
__replace_data = modify_with_jsonpath(__replace_data, 'baz[0].ab', 'changed')
|
|
|
|
print(f"Original Data:\n{dump_data(__data)}\n")
|
|
print(f"Modified Data:\n{dump_data(__replace_data)}\n")
|
|
print(f"Differences:\n{dump_data(DeepDiff(__data, __replace_data, verbose_level=2))}\n")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|
|
|
|
# __END__
|