Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 657

CSV/PPrint output/conversion from json via the command line (linux)

$
0
0

I'd like to get a csv/prettyprint output from the following json.

{"count": 28,"data": [    {"id": 100920,"name": "bam","_embedded": {"addresses": [          {"address": "10.244.134.115"          }        ]      }    },    {"id": 100983,"name": "testrecord","_embedded": {"addresses": [          {"address": "10.244.134.115"          }        ]      }    },    {"id": 101001,"name": "testrecord2lab","_embedded": {"addresses": [          {"address": "10.244.134.115"          }        ]      }    },    {"id": 101009,"name": "a","_embedded": {"addresses": [          {"address": "10.244.134.100"          }        ]      }    },    {"id": 101019,"name": "test","_embedded": {"addresses": [          {"address": "10.244.134.101"          }        ]      }    },    {"id": 101020,"name": "something","_embedded": {}    },    {"id": 101024,"name": "db","_embedded": {"addresses": [          {"address": "10.244.134.11"          }        ]      }    },    {"id": 101036,"name": "hello","_embedded": {"addresses": [          {"address": "192.168.30.102"          }        ]      }    },    {"id": 101037,"name": "external.com","_embedded": {"addresses": []      }    },    {"id": 101038,"name": "hey.dbacevic.com","_embedded": {"addresses": []      }    },    {"id": 101039,"name": "testexternal","_embedded": {}    },    {"id": 101043,"name": "ns1","_embedded": {"addresses": [          {"address": "10.244.134.134"          }        ]      }    },    {"id": 101044,"name": "cname","_embedded": {}    },    {"id": 101051,"name": "haha","_embedded": {"addresses": [          {"address": "10.244.134.102"          }        ]      }    },    {"id": 101063,"name": "testsomething","_embedded": {"addresses": [          {"address": "192.168.30.100"          }        ]      }    },    {"id": 101103,"name": "test","_embedded": {}    },    {"id": 101121,"name": "hostnamefromgateway","_embedded": {"addresses": [          {"address": "192.168.30.130"          }        ]      }    },    {"id": 101128,"name": "micetro-central","_embedded": {"addresses": [          {"address": "10.244.134.219"          }        ]      }    },    {"id": 101144,"name": "testingdhcp","_embedded": {"addresses": [          {"address": "191.168.200.242"          }        ]      }    },    {"id": 101167,"name": "testCNAME","_embedded": {}    },    {"id": 101168,"name": "testCNAMEtwo","_embedded": {}    },    {"id": 101169,"name": "test","_embedded": {}    },    {"id": 101170,"name": "test","_embedded": {}    },    {"id": 101174,"name": "asd","_embedded": {"addresses": [          {"address": "1.1.1.1"          }        ]      }    },    {"id": 101179,"name": "test","_embedded": {"addresses": [          {"address": "2.2.2.2"          }        ]      }    },    {"id": 101184,"name": "arrray1","_embedded": {"addresses": [          {"address": "3.3.3.3"          }        ]      }    },    {"id": 101189,"name": "array2","_embedded": {"addresses": [          {"address": "4.4.4.4"          }        ]      }    },    {"id": 101195,"name": "ghr","_embedded": {"addresses": [          {"address": "6.6.6.6"          }        ]      }    }  ]}

Something along the lines of:

id,name,address101121,hostnamefromgateway,192.168.30.130101128,micetro-central,10.244.134.219101144,testingdhcp,191.168.200.242101103,test,{}101037,external.com,[]101038,hey.dbacevic.com,[]...

So far I've been able to get a result like this using jq 'del(.count) | .data[]' | mlr --ijson --ocsv unsparsify.

Note: The input is from a curl and not from a file just to be clear.

id,name,_embedded.addresses.1.address100920,bam,10.244.134.115100983,testrecord,10.244.134.115101001,testrecord2lab,10.244.134.115101009,a,10.244.134.100101019,test,10.244.134.101id,name,_embedded101020,something,{}id,name,_embedded.addresses.1.address101024,db,10.244.134.11101036,hello,192.168.30.102id,name,_embedded.addresses101037,external.com,[]101038,hey.dbacevic.com,[]id,name,_embedded101039,testexternal,{}id,name,_embedded.addresses.1.address101043,ns1,10.244.134.134id,name,_embedded101044,cname,{}id,name,_embedded.addresses.1.address101051,haha,10.244.134.102101063,testsomething,192.168.30.100id,name,_embedded101103,test,{}id,name,_embedded.addresses.1.address101121,hostnamefromgateway,192.168.30.130101128,micetro-central,10.244.134.219101144,testingdhcp,191.168.200.242id,name,_embedded101167,testCNAME,{}101168,testCNAMEtwo,{}101169,test,{}101170,test,{}id,name,_embedded.addresses.1.address101174,asd,1.1.1.1101179,test,2.2.2.2101184,arrray1,3.3.3.3101189,array2,4.4.4.4101195,ghr,6.6.6.6

Is there a way to achieve what I need while only resorting to CLI and not some third party UI websites?


Viewing all articles
Browse latest Browse all 657

Trending Articles



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