I have a json array that looks as below -
[
{
"Code": "some code",
"Name": "some name",
"Country": "some country",
"Cost": "some cost",
"Type": "Some type"
},{
"Code": "some code",
"Name": "some name",
"Country": "some country",
"Cost": "some cost",
"Type": "Some type"
},{
"Code": "some code",
"Name": "some name",
"Country": "some country",
"Cost": "some cost",
"Type": "Some type"
}
]
I am trying print each json block on a new line with fields separated by '#'
Expected output
some code#some name#some country#some cost#some type
some code#some name#some country#some cost#some type
some code#some name#some country#some cost#some type
I've tried the code below which separates the content with '#'. However, it merges all blocks into a single line like this - some code#some name#some country#some cost#some type#some code#some name#some country#some cost#some type#some code#some name#some country#some cost#some type
cat contents.json | sed 's/^[ \t]*//;s/[ \t]*$//' | awk -F ': *' 'BEGIN { RS=",\n\"|\n}," } { gsub(/[\n\]\[\}]/,"",$2); if ($2) { printf("%s#", $2); } }'
Please could someone guide me to et this right?