Quantcast
Viewing all articles
Browse latest Browse all 522

How can jq read lines from a file and create valid a JSON?

I need help with creating a valid JSON file via jq which read lines from the file.

I have some text.txt file:

rabbit1-test1rabbit1-test2rabbit1-test3

And the bash-script:

VHOSTNAME=/NODENAME=node1input="test.txt"while IFS= read -r line; do jq -n \                  --arg a "$VHOSTNAME" \                  --arg b "$line"  \                  --arg c "$NODENAME" \'{"data": [{"{#VHOSTNAME}": $a, "{#QUEUENAME}": $b, "{#NODENAME}": $c}]}' ;done < "$input"

But, when I run the script, the JSON isn't valid:

{"data": [    {"{#VHOSTNAME}": "/","{#QUEUENAME}": "rabbit1-test1","{#NODENAME}": "node1"    }  ]}{"data": [    {"{#VHOSTNAME}": "/","{#QUEUENAME}": "rabbit1-test2","{#NODENAME}": "node1"    }  ]}{"data": [    {"{#VHOSTNAME}": "/","{#QUEUENAME}": "rabbit1-test3","{#NODENAME}": "node1"    }  ]}

I can't understand why jq reads file incorrectly.Please help me.


Viewing all articles
Browse latest Browse all 522

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>