jquery - convert json to another json format -
i new json. having little trouble inconverting json 1 format format. json converted.
{ "message": "successfully advisor data has been fetched.", "success": true, "data": { "dataheaders": ["carrier","b2b", "em"], "dataarray": { "dhl": ["dhl", "45", "5","5"], "fedex": ["fedex","40", "7","6"], "ups" : ["ups","30", "10","3"], "tnt" : ["tnt","30", "10","3"], } } }
i require json converted format.
[ { "key":"carrier", "values":[ { "x":"dhl", "y":45 }, { "x":"fedex", "y":40 }, { "x":"ups", "y":30 }, { "x":"tnt", "y":35 } ] }, { "key":"b2b", "values":[ { "x":"dhl", "y":5 }, { "x":"fedex", "y":7 }, { "x":"ups", "y":10 }, { "x":"tnt", "y":5 } ] }, { "key":"em", "values":[ { "x":"dhl", "y":5 }, { "x":"fedex", "y":6 }, { "x":"ups", "y":3 }, { "x":"tnt", "y":5 } ] } ]
how can using jquery?
use var obj = jquery.parsejson() parse input string. can access fields via obj.[fieldname] , build outputstring.
Comments
Post a Comment