pysimdjson icon indicating copy to clipboard operation
pysimdjson copied to clipboard

Printing JSON structure

Open VascoSch92 opened this issue 1 year ago • 3 comments

Hey, I am using pysimdjson very often to work with JSON and I appreciate the speed and the intuitiveness of the package. Generally, I use it when I need to look directly into specific JSON for information (debug mode).

However, when I start exploring a JSON it would be useful to have a function to print the structure (or the schema of the JSON) so that we can move faster.

i will give you an example. Suppose we have the JSON example:

{
  "owner": {
    "name": "Mike",
    "age": "24",
    "sex": "M"
  },
  "dogs": [
    {
      "name": "Charly",
      "age": 1,
      "sex": "M"
    },
    {
      "name": "Vanessa",
      "age": 2,
      "sex": "S"
    }
  ]
}

then i can write example.schema() (or example.structure() ) and the output will be:

root
 |- owner
 |   |- name
 |   |- age
 |   |- sex
 |- dogs
 |   |- array type
 |       |- name
 |       |- age
 |       |- sex

Is there already something in like that in the package?

VascoSch92 avatar Sep 28 '23 06:09 VascoSch92

This is exactly what I was looking for. It would also be very useful for me :-)

lneukom avatar Oct 09 '23 10:10 lneukom

Intriguing. Is there some kind of specification for such outputs?

lemire avatar Oct 09 '23 19:10 lemire

Nothing special... Just a tree with the json structure. It is not hard to implement it as a Python method but it slow.

VascoSch92 avatar Oct 20 '23 08:10 VascoSch92