There is for example json:

{ "SALUTATION": { "Hellow":"world" }, "SOMETHING": "bla bla bla Mr. Freeman" } 

From it you need to remove all the keys: SALUTATION , Hellow , SOMETHING using bash.

If you use jq 'keys':

 JSON='{ "SALUTATION": { "Hellow": "world" }, "SOMETHING": "bla bla bla Mr. Freeman" }' echo $JSON | jq 'keys' 

At the output I get ["SALUTATION", "SOMETHING"] , i.e. only keys of the first level. I want to understand how to display all the keys, regardless of what level they are on.

  • You have a bash tag, do you need to solve the problem using console utilities? Write what and how they tried to do, etc., on SO they do not solve other people's problems. - approximatenumber

2 answers 2

if we discard the possible repetition of keys in json, then something like this:

 $ JSON='{ "SALUTATION": { "Hellow": "world" }, "SOMETHING": "bla bla bla Mr. Freeman" }' $ echo $JSON | jq -r '. | paths[]'| sort -u Hellow SALUTATION SOMETHING 
  • Thank! Exactly what is needed! - z1650

The shell jtc I recently published, allows jtc to bypass all / any JSON elements (including keys). The result can already be processed using standard shell commands - discarding values ​​and sorting unique elements:

 bash $ JSON='{ "SALUTATION": { "Hellow": "world" }, "SOMETHING": "bla bla bla Mr. Freeman" }' bash $ echo $JSON | jtc -w'<.*>L:' -lr | sed 's/":.*/"/' | sort -u "Hellow" "SALUTATION" "SOMETHING" bash $