{"id":21253,"date":"2021-10-18T19:43:35","date_gmt":"2021-10-18T14:13:35","guid":{"rendered":"https:\/\/tutorial.eyehunts.com\/?p=21253"},"modified":"2022-11-25T18:14:20","modified_gmt":"2022-11-25T12:44:20","slug":"convert-python-list-to-json-example-code","status":"publish","type":"post","link":"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/","title":{"rendered":"Convert Python list to JSON | Example code"},"content":{"rendered":"\n<p>Use <a href=\"https:\/\/tutorial.eyehunts.com\/python\/json-dumps-python-function\/\">json.dumps()<\/a> function to convert a list to JSON in Python. This function takes a list as an argument and returns a JSON String.<\/p>\n\n\n\n<p><strong><em>Syntax<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import json\n\njsonString = json.dumps(list)<\/code><\/pre>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Python list to JSON example<\/strong><\/h2>\n\n\n\n<p>A simple example code takes a Python list with some <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-numbers-types-tutorial-example\/\">numbers <\/a>in it and converts it to a JSON string.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import json\n\naList = &#91;1, 2, 3]\nres = json.dumps(aList)\n\nprint(res)\nprint(type(res))\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: <\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" width=\"287\" height=\"115\" src=\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Convert-Python-list-to-JSON.jpg?resize=287%2C115&#038;ssl=1\" alt=\"Convert Python list to JSON\" class=\"wp-image-21291\"\/><\/figure><\/div>\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>How to Convert Python List of Dictionaries to JSON?<\/strong><\/h3>\n\n\n\n<p><strong>Answer<\/strong>: Same method son.dumps() will work for converting a list of dict into a JSON.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import json\n\naList = &#91;{'a': 1, 'b': 2}, {'c': 3, 'd': 4}]\nres = json.dumps(aList)\n\nprint(res)\n<\/code><\/pre>\n\n\n\n<p><strong>Output<\/strong>: [{&#8220;a&#8221;: 1, &#8220;b&#8221;: 2}, {&#8220;c&#8221;: 3, &#8220;d&#8221;: 4}]<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>Convert Python List of Lists to JSON<\/strong><\/h3>\n\n\n\n<p>You can convert the list into JSON using the dumps() method. First <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-import-module-library-package-file-system\/\">import <\/a>the json <a href=\"https:\/\/tutorial.eyehunts.com\/python\/python-modules-import-custom-builtin-package\/\">module <\/a>then use the method.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import json\n\naList = &#91;&#91;{'a': 1, 'b': 2}], &#91;{'c': 3, 'd': 4}]]\nres = json.dumps(aList)\n\nprint(res)\n<\/code><\/pre>\n\n\n\n<p>Output: [[{&#8220;a&#8221;: 1, &#8220;b&#8221;: 2}], [{&#8220;c&#8221;: 3, &#8220;d&#8221;: 4}]]<\/p>\n\n\n\n<div style=\"height:30px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<p>Do comment if you have any doubts or suggestions on this Python List tutorial.<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p><strong>Note:<\/strong> IDE:&nbsp;<a rel=\"noreferrer noopener\" href=\"https:\/\/www.jetbrains.com\/pycharm\/\" target=\"_blank\">PyCharm<\/a>&nbsp;2021.3.3 (Community Edition)<\/p><p>Windows 10<\/p><p><strong>Python 3.10.1<\/strong><\/p><p>All<strong>&nbsp;Python Examples&nbsp;are in&nbsp;Python&nbsp;3<\/strong>, so Maybe its different from python 2 or upgraded versions.<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>Use json.dumps() function to convert a list to JSON in Python. This function takes a list as an argument and returns a JSON String. Syntax Python list to JSON example A simple example code takes a Python list with some numbers in it and converts it to a JSON string. Output: How to Convert Python&hellip;&nbsp;<a href=\"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/\" rel=\"bookmark\">Read More &raquo;<span class=\"screen-reader-text\">Convert Python list to JSON | Example code<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"neve_meta_sidebar":"","neve_meta_container":"","neve_meta_enable_content_width":"","neve_meta_content_width":0,"neve_meta_title_alignment":"","neve_meta_author_avatar":"","neve_post_elements_order":"","neve_meta_disable_header":"","neve_meta_disable_footer":"","neve_meta_disable_title":"","jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[30],"tags":[235,83],"post_series":[],"class_list":["post-21253","post","type-post","status-publish","format-standard","hentry","category-python","tag-python-json","tag-python-list"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.1.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Convert Python list to JSON | Example code<\/title>\n<meta name=\"description\" content=\"Use json.dumps() function to convert list to JSON in Python. This function takes a list as an argument and returns a JSON String.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Convert Python list to JSON | Example code\" \/>\n<meta property=\"og:description\" content=\"Use json.dumps() function to convert list to JSON in Python. This function takes a list as an argument and returns a JSON String.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/\" \/>\n<meta property=\"og:site_name\" content=\"Tutorial\" \/>\n<meta property=\"article:published_time\" content=\"2021-10-18T14:13:35+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-11-25T12:44:20+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Convert-Python-list-to-JSON.jpg\" \/>\n<meta name=\"author\" content=\"Rohit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Rohit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/\",\"name\":\"Convert Python list to JSON | Example code\",\"isPartOf\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Convert-Python-list-to-JSON.jpg\",\"datePublished\":\"2021-10-18T14:13:35+00:00\",\"dateModified\":\"2022-11-25T12:44:20+00:00\",\"author\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\"},\"description\":\"Use json.dumps() function to convert list to JSON in Python. This function takes a list as an argument and returns a JSON String.\",\"breadcrumb\":{\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Convert-Python-list-to-JSON.jpg?fit=287%2C115&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Convert-Python-list-to-JSON.jpg?fit=287%2C115&ssl=1\",\"width\":287,\"height\":115},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/tutorial.eyehunts.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Convert Python list to JSON | Example code\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#website\",\"url\":\"https:\/\/tutorial.eyehunts.com\/\",\"name\":\"Tutorial\",\"description\":\"By EyeHunts\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1\",\"name\":\"Rohit\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"contentUrl\":\"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971\",\"caption\":\"Rohit\"},\"description\":\"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.\",\"url\":\"https:\/\/tutorial.eyehunts.com\/author\/rohit\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Convert Python list to JSON | Example code","description":"Use json.dumps() function to convert list to JSON in Python. This function takes a list as an argument and returns a JSON String.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/","og_locale":"en_US","og_type":"article","og_title":"Convert Python list to JSON | Example code","og_description":"Use json.dumps() function to convert list to JSON in Python. This function takes a list as an argument and returns a JSON String.","og_url":"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/","og_site_name":"Tutorial","article_published_time":"2021-10-18T14:13:35+00:00","article_modified_time":"2022-11-25T12:44:20+00:00","og_image":[{"url":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Convert-Python-list-to-JSON.jpg","type":"","width":"","height":""}],"author":"Rohit","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Rohit","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/","url":"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/","name":"Convert Python list to JSON | Example code","isPartOf":{"@id":"https:\/\/tutorial.eyehunts.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/#primaryimage"},"image":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/#primaryimage"},"thumbnailUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Convert-Python-list-to-JSON.jpg","datePublished":"2021-10-18T14:13:35+00:00","dateModified":"2022-11-25T12:44:20+00:00","author":{"@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1"},"description":"Use json.dumps() function to convert list to JSON in Python. This function takes a list as an argument and returns a JSON String.","breadcrumb":{"@id":"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/#primaryimage","url":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Convert-Python-list-to-JSON.jpg?fit=287%2C115&ssl=1","contentUrl":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Convert-Python-list-to-JSON.jpg?fit=287%2C115&ssl=1","width":287,"height":115},{"@type":"BreadcrumbList","@id":"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-example-code\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/tutorial.eyehunts.com\/"},{"@type":"ListItem","position":2,"name":"Convert Python list to JSON | Example code"}]},{"@type":"WebSite","@id":"https:\/\/tutorial.eyehunts.com\/#website","url":"https:\/\/tutorial.eyehunts.com\/","name":"Tutorial","description":"By EyeHunts","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/tutorial.eyehunts.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/69ca2cb8c13fdce0ee5b39d6175119b1","name":"Rohit","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/tutorial.eyehunts.com\/#\/schema\/person\/image\/","url":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","contentUrl":"https:\/\/tutorial.eyehunts.com\/wp-content\/litespeed\/avatar\/2b27529b86d6dfb5336897e07c93a827.jpg?ver=1777374971","caption":"Rohit"},"description":"Degree in Computer Science and Engineer: App Developer and has multiple Programming languages experience. Enthusiasm for technology &amp; like learning technical.","url":"https:\/\/tutorial.eyehunts.com\/author\/rohit\/"}]}},"jetpack_featured_media_url":"","jetpack-related-posts":[{"id":21294,"url":"https:\/\/tutorial.eyehunts.com\/python\/convert-python-list-to-json-array-example-code\/","url_meta":{"origin":21253,"position":0},"title":"Convert Python list to JSON array | Example code","author":"Rohit","date":"October 19, 2021","format":false,"excerpt":"Use json dumps() to convert a list to a JSON array in Python. The dumps() function takes a list as an argument and returns a JSON String. json.dumps(obj) Python list to JSON array example Simple example code converting given list [\"1\", \"2\", \"3\"] to a JSON array results in the\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"Python list to JSON array","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-list-to-JSON-array.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":21311,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-json-to-string-example-code\/","url_meta":{"origin":21253,"position":1},"title":"Python JSON to string | Example code","author":"Rohit","date":"October 20, 2021","format":false,"excerpt":"Using json.dumps() can convert JSON to string in Python. It would always produce a valid JSON string (assuming everything inside the object is serializable). Python JSON to string example Simple example code dumps() would convert None into null making a valid JSON string that can be loaded: import json json_obj\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Convert-Json-to-String-with-API.jpg?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Convert-Json-to-String-with-API.jpg?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Convert-Json-to-String-with-API.jpg?resize=525%2C300&ssl=1 1.5x"},"classes":[]},{"id":21241,"url":"https:\/\/tutorial.eyehunts.com\/python\/json-dumps-python-function\/","url_meta":{"origin":21253,"position":2},"title":"JSON dumps Python | Function","author":"Rohit","date":"October 22, 2021","format":false,"excerpt":"Python JSON dumps() function converts a Python object into a json string. This function is used when the objects are required to be in string format and is used for parsing, printing, etc. json.dumps(obj, indent=4) Example JSON dumps Python Simple example code passing the Python dictionary to json.dumps() function will\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"JSON dumps Python","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/JSON-dumps-Python.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":21321,"url":"https:\/\/tutorial.eyehunts.com\/python\/import-json-in-python\/","url_meta":{"origin":21253,"position":3},"title":"Import JSON in Python","author":"Rohit","date":"October 21, 2021","format":false,"excerpt":"Python has a built-in json module, which can be used to work with JSON data. See below the syntax of Import the json module: JSON can store Lists, bools, numbers, tuples, and dictionaries. import json The JSON module is mainly used to convert the python dictionary above into a JSON\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Import-JSON-in-Python.gif?resize=350%2C200&ssl=1","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Import-JSON-in-Python.gif?resize=350%2C200&ssl=1 1x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Import-JSON-in-Python.gif?resize=525%2C300&ssl=1 1.5x, https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Import-JSON-in-Python.gif?resize=700%2C400&ssl=1 2x"},"classes":[]},{"id":21296,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-list-of-objects-to-json-example-code\/","url_meta":{"origin":21253,"position":4},"title":"Python list of objects to JSON | Example code","author":"Rohit","date":"October 20, 2021","format":false,"excerpt":"You can use a list comprehension to produce a list of dictionaries, then convert that using json.dumps() function. Convert Python list of objects to JSON example A simple example codes a dump method in your object and uses it when sending things to json module: import json class IpPort: def\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-list-of-objects-to-JSON.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":21247,"url":"https:\/\/tutorial.eyehunts.com\/python\/python-dict-to-json-example-code\/","url_meta":{"origin":21253,"position":5},"title":"Python dict to JSON | Example code","author":"Rohit","date":"October 26, 2021","format":false,"excerpt":"Use the JSON dumps() method to convert dict to JSON string in Python. It's a built-in function that converts the dictionary to a string object, not the json(dictionary) object! Python dict to JSON example In simple example code we have defined one dictionary and then convert that dictionary to JSON\u2026","rel":"","context":"In &quot;Python&quot;","block_context":{"text":"Python","link":"https:\/\/tutorial.eyehunts.com\/category\/python\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/tutorial.eyehunts.com\/wp-content\/uploads\/2021\/10\/Python-dict-to-JSON.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/21253","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/comments?post=21253"}],"version-history":[{"count":1,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/21253\/revisions"}],"predecessor-version":[{"id":34459,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/posts\/21253\/revisions\/34459"}],"wp:attachment":[{"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/media?parent=21253"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/categories?post=21253"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/tags?post=21253"},{"taxonomy":"post_series","embeddable":true,"href":"https:\/\/tutorial.eyehunts.com\/wp-json\/wp\/v2\/post_series?post=21253"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}