daily pastebin goal
19%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 72 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {   "items": [
  2.      "number": {
  3.        "value": 23
  4.        "label": test
  5.     }
  6. ]
  7. }
  8.      
  9. #!/usr/bin/python
  10.  
  11. import json
  12.  
  13. myjson = {'items':[]}
  14. d = {}
  15. d['value'] = 23
  16. d['label'] = "test"
  17. myjson.get('items').append(d)
  18. output = json.dumps(myjson)
  19. print output
  20.      
  21. {
  22. "items": [{
  23.   "value": 23,
  24.   "label": "test"}
  25. ]}
  26.      
  27. { "items":
  28.     [
  29.        {
  30.        "number":
  31.            {
  32.            "value": 23,
  33.            "label": "test"
  34.            }
  35.        }
  36.     ]
  37. }
  38.      
  39. jdict = json.loads(yourjson)
  40.  jdict['items'] => [{"number":{...}}]
  41.  jdict['items'][0] => {"number":{...}}
  42.  jdict['items'][0]['number']['value'] => 23
  43.      
  44. myjson.get('items').append({'number': d})
  45.      
  46. import json
  47.  
  48. myjson = {'msg':[]}
  49. d = {}
  50. d['phrase'] = "event1"
  51. d['start'] = "11.22.2018"
  52. d['end'] = "11.28.2018"
  53. myjson.get('msg').append({'phrase': d})
  54. output = json.dumps(myjson)
  55. print(output)
  56.      
  57. {
  58.   "msg": [
  59.     {
  60.       "phrase": {
  61.         "phrase": "event1",
  62.         "start": "11.22.2018",
  63.         "end": "11.28.2018"
  64.       }
  65.     }
  66.   ]
  67. }
  68.      
  69. {
  70.   "msg": [
  71.     {
  72.       "phrase": "event1"{
  73.         [
  74.           {
  75.             "start": "11.22.2018",
  76.             "end": "11.28.2018"
  77.           }
  78.           {
  79.             "start": "11.22.2018",
  80.             "end": "11.28.2018"
  81.           }
  82.         ]
  83.       }
  84.     }
  85.   ]
  86. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top