java - Convert JSONObject into JSONArray using Python -


i have gone through various threads, couldn't find particular answer in python. have json file

{     "storeid" : "123",     "status" : 3,     "data" : {             "response" : {                     "section" : "25",                     "elapsed" : 277.141,                     "products" : {                             "prd_1": {                                     "price" : 11.99,                                     "qty" : 10,                                     "upc" : "0787493"                             },                             "prd_2": {                                     "price" : 9.99,                                     "qty" : 2,                                     "upc" : "0763776"                             },                             "prd_3": {                                     "price" : 29.99,                                     "qty" : 8,                                     "upc" : "9948755"                             }                     },                     "type" : "tagged"             }     } } 

i need convert json file format below, changing json object 'products' array form.

{     "storeid" : "123",     "status" : 3,     "data" : {             "response" : {                     "section" : "25",                     "elapsed" : 277.141,                     "products" : [                             {                                     "price" : 11.99,                                     "qty" : 10,                                     "upc" : "0787493"                             },                             {                                     "price" : 9.99,                                     "qty" : 2,                                     "upc" : "0763776"                             },                             {                                     "price" : 29.99,                                     "qty" : 8,                                     "upc" : "9948755"                             }                     ],                     "type" : "tagged"             }     } } 

is there way in python. saw people using java, not in python. can please let me know way in python.

just values() of products dictionary , give array of values. code below works me assuming json in file1.txt note

import json open('file1.txt') jdata:     data = json.load(jdata)     d = data d["data"]["response"]["products"] = d["data"]["response"]["products"].values() print(json.dumps(d)) 

output:

{"status": 3, "storeid": "123", "data": {"type": "tagged", "response": {"section": "25", "products": [{"price": 9.99, "upc": "0763776", "qty": 2}, {"price": 29.99, "upc": "9948755", "qty": 8}, {"price": 11.99, "upc": "0787493", "qty": 10}], "elapsed": "277.141"}}} 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -