Reshape JSON by collapsing nested data

Published: Sunday, Sep 20, 2020 Last modified: Monday, Dec 9, 2024

This worked for me:

curl http-that-url | jq '[.[] | {id: ._id} + ._source]' | sqlite-utils insert data.db items - --alter

— Simon Willison (@simonw) September 19, 2020

Here I am collapsing the “_source” key, I.e. getting rid of it.

curl https://s.natalian.org/2020-09-19/sample.json | jq 'map(del(._source) + ._source)'