I have a JSON file as below.
{
"card":{
"cardName":"10AN10G",
"portSignalRates":[
"10AN10G-1-OTU2",
"10AN10G-1-OTU2E",
"10AN10G-1-TENGIGE",
"10AN10G-1-STM64"
],
"listOfPort":{
"10AN10G-1-OTU2":{
"portAid":"10AN10G-1-OTU2",
"signalType":"OTU2",
"tabNames":[
"PortDetails"
],
"requestType":{
"PortDetails":"PTP"
},
"paramDetailsMap":{
"PortDetails":[
{
"type":"dijit.form.TextBox",
"name":"signalType",
"title":"Signal Rate",
"id":"",
"options":[
],
"label":"",
"value":"OTU2",
"checked":"",
"enabled":"false",
"selected":""
},
{
"type":"dijit.form.TextBox",
"name":"userLabel",
"title":"Description",
"id":"",
"options":[
],
"label":"",
"value":"",
"checked":"",
"enabled":"true",
"selected":""
},
{
"type":"dijit.form.Select",
"name":"Frequency",
"title":"Transmit Frequency"
}
]
}
}
}
}
}
I require the output to be:
signalType:"Signal Rate",
userLabel:"Description",
Frequency:"Transmit Frequency",.. ,.....
I tried with:
grep -oP '(?<=\"title\":\")[^"]*' file > outfile
but this just splits the value of title and returns.
Can I use perl to access elements of the JSON data that I want?
jqis a nifty command line filter for json of the sed/awk sort. stedolan.github.io/jqjq,json_verifyto check the work. My thinking was a basic question like this might be useful to answer (even repeatedly), but that it needed proper data to be useful. I would not be surprised if it was a duplicate of another SO post (e.g. see this one on JSON and perl). But I think that is OK :-)