Fetching the key names from a JSON document using jq
is simple!
Get key names of JSON using jq
Given a file named example.json
,
|
|
extracting the keys in alphabetical order can be completed using:
|
|
Output:
|
|
Get key names of JSON unsorted using jq
Taking the previous JSON document example.json
, the keys may be returned in order as they appear:
|
|
Output:
|
|
Get key names of JSON in array of objects using jq
Given a file named example.json
,
|
|
extracting the keys from the nested array of objects can be completed using:
|
|
Output:
|
|
If the list is required without the brackets:
|
|
Output:
|
|
Removing the quotes is also an option:
|
|
Output:
|
|