Skip to content

Instantly share code, notes, and snippets.

@nkentaro
Created February 6, 2018 14:48
Show Gist options
  • Save nkentaro/6d28dcc04c88e33492c54117edbf0399 to your computer and use it in GitHub Desktop.
Save nkentaro/6d28dcc04c88e33492c54117edbf0399 to your computer and use it in GitHub Desktop.
Nested dict to nested JSON
from your_own_facility import YourOwnWSService
ws = YourOwnWSService('wss://example.com/WSAPI/')
message = {
"m": 0,
"i": 55,
"n": "YourName",
"o": ""
}
payload = {
"OMSId": 1,
"ProductId": i+1
}
message['o'] = json.dumps(payload) # you need to encode dict if you have a child dict
ws.send(json.dumps(message)) # and you would need to encode the outer dict again to make a correct JSON
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment