Skip to main content
Bumped by Community user
edited tags
Link
Kusalananda
  • 356.2k
  • 42
  • 737
  • 1.1k
Source Link

convert JSON array to space separated string

I have a JSON file like this:

{
 "name" : "Allow",
 "source" : [ "*" ,"0.0.0.0"]
}

I need to parse this JSON so the array of strings inside JSON can convert to "space separated string". I later need to supply these variables to another function like this:

local file="file-name"
while read val; do
    local name
    local source

    name=$(jq --raw-output '.name' <<< ${val})
    source=$(jq --raw-output '.source' <<< ${val})
__test "${name}" "${source}" 
  done < <(cat ${file} | jq -rc '.[]')

So,I basically need to change source to a string and pass it, rather than a list of strings.