Using Miller (mlr
), which is able to convert between several common structured formats, we can get it to read the JSON input, relabel the unfortunately labelled key into just key
, flatten the data and pull out the key.entityId
field's value. The output is in "NIDX" (index-numbered (toolkit style)) format which is header-less and suits this application.
$ mlr --j2n label key then flatten then cut -f key.entityId file.json
GoUZm0F3r-rZ0tItdurVfPLCAfBGrnvF32
The --j2n
option is a shorthand for --ijson
(input JSON) together with --onidx
(output NIDX).
Approximately the same operation using jq
(a very common JSON processor):
$ jq -r '.[].entityId' file.json
GoUZm0F3r-rZ0tItdurVfPLCAfBGrnvF32
In both these commands, we don't really care about the top-level key and instead go for the value of the entityId
key in the inner structure. JSON documents should generally store data in values, not in keys. If they don't, it's a good sign they should have used an array instead.