{"id":1511,"date":"2023-05-21T08:31:59","date_gmt":"2023-05-21T08:31:59","guid":{"rendered":"https:\/\/itnotes.apjsoftwares.com\/?p=1511"},"modified":"2023-05-21T08:31:59","modified_gmt":"2023-05-21T08:31:59","slug":"explain-in-detail-json-to-python-decoding-with-example","status":"publish","type":"post","link":"https:\/\/itnotes.apjsoftwares.in\/index.php\/2023\/05\/21\/explain-in-detail-json-to-python-decoding-with-example\/","title":{"rendered":"Explain in detail JSON to Python (Decoding) with example"},"content":{"rendered":"\n<p>JSON string decoding is done with the help of inbuilt method&nbsp;<code>json.loads()<\/code>&nbsp;&amp;&nbsp;<code>json.load()&nbsp;<\/code>of JSON library in Python.<\/p>\n\n\n\n<p>Here translation table show example of JSON objects to Python objects which are helpful to perform decoding in Python of JSON string.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>JSON<\/th><th>Python<\/th><\/tr><\/thead><tbody><tr><td>Object<\/td><td>Dict<\/td><\/tr><tr><td>Array<\/td><td>List<\/td><\/tr><tr><td>String<\/td><td>Unicode<\/td><\/tr><tr><td>number \u2013 int<\/td><td>Number \u2013 int, long<\/td><\/tr><tr><td>number \u2013 real<\/td><td>Float<\/td><\/tr><tr><td>True<\/td><td>True<\/td><\/tr><tr><td>False<\/td><td>False<\/td><\/tr><tr><td>Null<\/td><td>None<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The basic JSON to Python example of decoding with the help of json.loads function:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">import json  # json library imported\n# json data string\nperson_data = '{  \"person\":  { \"name\":  \"Kenn\",  \"sex\":  \"male\",  \"age\":  28}}'\n# Decoding or converting JSON format in dictionary using loads()\ndict_obj = json.loads(person_data)\nprint(dict_obj)\n# check type of dict_obj\nprint(\"Type of dict_obj\", type(dict_obj))\n# get human object details\nprint(\"Person......\",  dict_obj.get('person'))<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>JSON string decoding is done with the help of inbuilt method&nbsp;json.loads()&nbsp;&amp;&nbsp;json.load()&nbsp;of JSON library in Python&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[20],"tags":[],"_links":{"self":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1511"}],"collection":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/comments?post=1511"}],"version-history":[{"count":1,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1511\/revisions"}],"predecessor-version":[{"id":1512,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/posts\/1511\/revisions\/1512"}],"wp:attachment":[{"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/media?parent=1511"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/categories?post=1511"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itnotes.apjsoftwares.in\/index.php\/wp-json\/wp\/v2\/tags?post=1511"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}