json - Get list of all values in a key:value list -


so input looks like

{"selling":"0","quantity":"2","price":"80000","date":"1401384212","rs_name":"overhault","contact":"pm","notes":""}  {"selling":"0","quantity":"100","price":"80000","date":"1401383271","rs_name":"sammvarnish","contact":"pm","notes":"seers bank w321 :)"}  {"selling":"0","quantity":"100","price":"70000","date":"1401383168","rs_name":"pwnoramaa","contact":"pm","notes":""} 

and output want must like

 0,2,80000,1401384212,overhault,pm,""  0,100,80000,1401383271,sammvarnish,pm,"seers bank w321 :)"  0,100,70000,1401383168,pwnoramaa,pm,"" 

what's best way in bash?

edit: changed needs. new output want is, {"selling":"0","quantity":"2","price":"80000","date":"1401384212","rs_name":"overhault","contact":"pm","notes":"testnote"} input,

rs name: \t overhault quantity: \t 2 price: \t 80000 date: \t 29-05 19:23 contact: \t pm notes: \t testnote 

where \t tab character (like in echo "\t"). can see, 1 tad bit more complicated. example, changes order, , requires unix timestamp converted alternative format.

i'll use tool can offer me long explain how can use bash script. input consist of 3 of such lines, delimited newline character, , must print output empty line between each of results.

don't regular expressions/bash, there json parsers kind of task. simple python example:

import json data = json.loads('{"selling":"0","quantity":"2"}') data = ','.join(data.values()) print(data) 

i suggest use simple script make executable , call.

edit: here's version preserves order:

 import json  data = json.loads('{"selling":"0","quantity":"2", "price":"80000"}')  orderedkeys = ['selling', 'quantity', 'price']  values = [data[key] key in orderedkeys]  values = ','.join(values)  print(values) 

output:

 0,2,80000  

Comments

Popular posts from this blog

php - render data via PDO::FETCH_FUNC vs loop -

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

The canvas has been tainted by cross-origin data in chrome only -