1

I am having this issue that I want to read values from a json string in BASH and pass them on to a bash command. Basicly I want to transform e.g.:

{first: a, second: b} -> first=a second=b
{first: a, second: b, third: c} -> first=a second=b third=c
{1: a, 2:b} -> 1=a, 2=b

How would I do that so it will work no matter how many key-value pairs there are in the json string?

so far I have gotten this far:

a='{"first": "a", "second": "b"}'
echo ${a} | jq -r 'to_entries | .[] | .key + "=" + .value'
first=a
second=b

But I want it to be on the same line separated by " "

smallbirds
  • 877
  • 12
  • 35

1 Answers1

1

You can use a tool called jq to pass the JSON into a command, and this would be encoded also if required, with many more features included.

More information can be found on the following link, https://stedolan.github.io/jq/

Shaqil Ismail
  • 1,794
  • 1
  • 4
  • 5