Programming Tip -How can I convert Python dictionary to JavaScript Json hash table?

in #steemit6 years ago

Programming Tip -How can I convert Python dictionary to JavaScript Json hash table?

Javascripthon-python-js-converter.jpg


Today i am going to show Programming Tip - How can I convert Python dictionary to JavaScript hash table with simple code. I hope you will understand this.
If you have any query you can ask.
i hope you will like it.


The dumps function converts the dict to a string. For example,

import json
my_dict = {
   'foo': 42,'bar': {
      'baz': "Hello",'poo': 124.2
   }
}
my_json = json.dumps(my_dict)
print(my_json)

This will give the output:

'{"foo": 42, "bar": {"baz": "Hello", "poo": 124.2}}'


The load's function converts the string back to a dict. For example,

import json
my_str = '{"foo": 42, "bar": {"baz": "Hello", "poo": 124.2}}'
my_dict = json.loads(my_str)
print(my_dict['bar']['baz'])


This will give the output:

Hello
On the JS side of things, you don't need to do anything. This is because JSON literally means JavaScript Object Notation. 


Follow me at : https://steemit.com/@ahmadhassan
=========================================================


Thanks for reading and always welcome your suggestions :) =========================================================

Coin Marketplace

STEEM 0.28
TRX 0.11
JST 0.034
BTC 66272.75
ETH 3183.00
USDT 1.00
SBD 4.09