A simple command-line tool to flatten JSON objects using JSON Pointer-style keys.
Essentially a tiny wrapper around single call to json-pointer.flatten
.
- nodejs
- npm
git clone [email protected]:hjmeijer/json-flatten.git
cd json-flatten
npm install -g
Reading from file:
$ cat <<EOF > data.json
{
"name": "John",
"cars": [
{
"brand": "Ford",
"type": "Taunus"
},
{
"brand": "Nissan",
"type": "Micra"
}
]
}
EOF
$ json-flatten data.json
{ '/name': 'John',
'/cars/0/brand': 'Ford',
'/cars/0/type': 'Taunus',
'/cars/1/brand': 'Nissan',
'/cars/1/type': 'Micra' }
With input from stdin:
$ cat data.json | json-flatten
{ '/name': 'John',
'/cars/0/brand': 'Ford',
'/cars/0/type': 'Taunus',
'/cars/1/brand': 'Nissan',
'/cars/1/type': 'Micra' }