Skip to content
This repository has been archived by the owner on Jun 17, 2021. It is now read-only.
/ py-jd Public archive

PY-JD is an algorithm written in Python that iterates through all JSON object properties using Tree Traverse technique and describes distinct information in three different patterns for easy diff check.

License

Notifications You must be signed in to change notification settings

Devwarlt/py-jd

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 

Repository files navigation

PY-JD: Python JSON Descriptor license-badge size-badge visitors-badge

PY-JD is an algorithm written in Python that iterates through all JSON object properties using Tree Traverse technique and describes distinct information in three different patterns for easy diff check.

Languages

python-language-badge

Usage

Consider this JSON input:

sample.json
{
    "glossary": {
        "title": "example glossary",
        "GlossDiv": {
            "title": "S",
            "GlossList": {
                "GlossEntry": {
                    "ID": "SGML",
                    "SortAs": "SGML",
                    "GlossTerm": "Standard Generalized Markup Language",
                    "Acronym": "SGML",
                    "Abbrev": "ISO 8879:1986",
                    "GlossDef": {
                        "para": "A meta-markup language, used to create markup languages such as DocBook.",
                        "GlossSeeAlso": ["GML", "XML"]
                    },
                    "GlossSee": "markup"
                }
            }
        }
    }
}

Must import references from module json_descriptor, see example below:

import json_descriptor
import json


file_path: str = 'sample.json'
with open(file_path, 'r', encoding='utf8') as file:
  content_str: str = file.read()
  content: dict = json.loads(content_str)
  regular_navigation, json_contract, jmespath_list = json_descriptor.get_descriptor_details(content)
  with open(file_path.replace('.json', '-regular_navigation.txt'), 'w', encoding='utf8') as regular_navigation_file:
      regular_navigation_file.write(regular_navigation)
  with open(file_path.replace('.json', '-json_contract.json'), 'w', encoding='utf8') as json_contract_file:
      json_contract_file.write(json_contract)
  with open(file_path.replace('.json', '-jmespath_list.json'), 'w', encoding='utf8') as jmespath_list_file:
      jmespath_list_file.write(jmespath_list)

Patterns:

Pattern 1 - Regular Navigation:

sample-regular_navigation.txt
[+] root (type: dict)
.[+] glossary (type: dict) | (JMESPath: glossary[])
..[-] title (type: str) | (JMESPath: glossary[].title)
..[+] GlossDiv (type: dict) | (JMESPath: glossary[].GlossDiv[])
...[-] title (type: str) | (JMESPath: glossary[].GlossDiv[].title)
...[+] GlossList (type: dict) | (JMESPath: glossary[].GlossDiv[].GlossList[])
....[+] GlossEntry (type: dict) | (JMESPath: glossary[].GlossDiv[].GlossList[].GlossEntry[])
.....[-] ID (type: str) | (JMESPath: glossary[].GlossDiv[].GlossList[].GlossEntry[].ID)
.....[-] SortAs (type: str) | (JMESPath: glossary[].GlossDiv[].GlossList[].GlossEntry[].SortAs)
.....[-] GlossTerm (type: str) | (JMESPath: glossary[].GlossDiv[].GlossList[].GlossEntry[].GlossTerm)
.....[-] Acronym (type: str) | (JMESPath: glossary[].GlossDiv[].GlossList[].GlossEntry[].Acronym)
.....[-] Abbrev (type: str) | (JMESPath: glossary[].GlossDiv[].GlossList[].GlossEntry[].Abbrev)
.....[+] GlossDef (type: dict) | (JMESPath: glossary[].GlossDiv[].GlossList[].GlossEntry[].GlossDef[])
......[-] para (type: str) | (JMESPath: glossary[].GlossDiv[].GlossList[].GlossEntry[].GlossDef[].para)
......[+] GlossSeeAlso (type: list) | (JMESPath: glossary[].GlossDiv[].GlossList[].GlossEntry[].GlossDef[].GlossSeeAlso[])
.......[-] field of 'GlossSeeAlso' (type: str) | (JMESPath: glossary[].GlossDiv[].GlossList[].GlossEntry[].GlossDef[].GlossSeeAlso[])
.....[-] GlossSee (type: str) | (JMESPath: glossary[].GlossDiv[].GlossList[].GlossEntry[].GlossSee)

Pattern 2 - JSON Contract:

sample-json_contract.json
{
    "root": [{
        "glossary": [{
                "title": "str"
            },
            {
                "GlossDiv": [{
                        "title": "str"
                    },
                    {
                        "GlossList": [{
                            "GlossEntry": [{
                                    "ID": "str"
                                },
                                {
                                    "SortAs": "str"
                                },
                                {
                                    "GlossTerm": "str"
                                },
                                {
                                    "Acronym": "str"
                                },
                                {
                                    "Abbrev": "str"
                                },
                                {
                                    "GlossDef": [{
                                            "para": "str"
                                        },
                                        {
                                            "GlossSeeAlso": [{
                                                "field of 'GlossSeeAlso'": "str"
                                            }]
                                        }
                                    ]
                                },
                                {
                                    "GlossSee": "str"
                                }
                            ]
                        }]
                    }
                ]
            }
        ]
    }]
}

Pattern 3 - JMESPath List:

sample-jmespath_list.json
[
    "",
    "glossary[]",
    "glossary[].GlossDiv[]",
    "glossary[].GlossDiv[].GlossList[]",
    "glossary[].GlossDiv[].GlossList[].GlossEntry[]",
    "glossary[].GlossDiv[].GlossList[].GlossEntry[].Abbrev",
    "glossary[].GlossDiv[].GlossList[].GlossEntry[].Acronym",
    "glossary[].GlossDiv[].GlossList[].GlossEntry[].GlossDef[]",
    "glossary[].GlossDiv[].GlossList[].GlossEntry[].GlossDef[].GlossSeeAlso[]",
    "glossary[].GlossDiv[].GlossList[].GlossEntry[].GlossDef[].GlossSeeAlso[]",
    "glossary[].GlossDiv[].GlossList[].GlossEntry[].GlossDef[].para",
    "glossary[].GlossDiv[].GlossList[].GlossEntry[].GlossSee",
    "glossary[].GlossDiv[].GlossList[].GlossEntry[].GlossTerm",
    "glossary[].GlossDiv[].GlossList[].GlossEntry[].ID",
    "glossary[].GlossDiv[].GlossList[].GlossEntry[].SortAs",
    "glossary[].GlossDiv[].title",
    "glossary[].title"
]

Contributors

  • Nádio ~ @Devwarlt
  • UnB Back-end Developers ~ Cortex Team

About

PY-JD is an algorithm written in Python that iterates through all JSON object properties using Tree Traverse technique and describes distinct information in three different patterns for easy diff check.

Topics

Resources

License

Stars

Watchers

Forks

Languages