sqlitebiter icon indicating copy to clipboard operation
sqlitebiter copied to clipboard

Flatten JSON

Open thombashi opened this issue 6 years ago • 2 comments

Flatten JSON which has JSON schema format currently not supported before converting.

Poll: https://github.com/thombashi/sqlitebiter/discussions/89

thombashi avatar Nov 20 '18 12:11 thombashi

I do this by pre-processing my files with jq. Give the following:

flatten.json:

[
  {
    "a": {
      "b": 1,
      "c": 2
    }
  },
  {
    "a": {
      "b": 3,
      "c": 4
    }
  }
]

flatten.jq:

map([ leaf_paths as $path | { key: $path|join("."), value: getpath($path) } ]|from_entries)

the command jq -f flatten.jq flatten.json will produce the following output:

[
  {
    "a.b": 1,
    "a.c": 2
  },
  {
    "a.b": 3,
    "a.c": 4
  }
]

irgeek avatar Sep 19 '19 02:09 irgeek

https://github.com/thombashi/sqlitebiter/discussions/89

thombashi avatar Aug 19 '22 10:08 thombashi