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

in #utopian-io3 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 :) =========================================================

Sort:  

I downvoted your post because you were using the utopian tag to spam that tag.

down voted for what reason. Utopian for education tag so i am sharing my programming tips on that. i don't think so it's spam.
without any warning how can you down vote my post. ? i need the reason

Utopian tag is not for education, but posts made via the utopian web interface or posts that are expected to be reviewed by the utopian team and written in a proper template format. Your post is not related to that.

ok i didn't know about that .
but doesn't mean you down-voted my post. take it back or send me guidelines link where i can learn proper about this tag

This post has received a 0.50 % upvote from @booster thanks to: @ahmadhassan.