{"id":853,"date":"2024-09-03T22:22:28","date_gmt":"2024-09-03T17:22:28","guid":{"rendered":"https:\/\/augurytech.co.uk\/courses\/?p=853"},"modified":"2024-10-05T09:04:10","modified_gmt":"2024-10-05T04:04:10","slug":"python-json-file","status":"publish","type":"post","link":"https:\/\/augurytech.co.uk\/courses\/python\/python-json-file\/","title":{"rendered":"Python: JSON File"},"content":{"rendered":"\n<div class=\"wp-block-group is-vertical is-content-justification-stretch is-layout-flex wp-container-core-group-is-layout-353c4f5a wp-block-group-is-layout-flex\">\n<h3 class=\"wp-block-heading has--font-size\">Writing Python List in JSON File<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>import json\nalphabet_letters = &#91;\"a\", \"b\", \"c\"]<\/strong>\n<strong>\nwith open(\"alphabet_list.json\", \"w\") as f:\n  json.dump(alphabet_letters, f)<\/strong><\/code><\/pre>\n<\/div>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-group is-vertical is-content-justification-stretch is-layout-flex wp-container-core-group-is-layout-353c4f5a wp-block-group-is-layout-flex\">\n<h3 class=\"wp-block-heading has--font-size\">Writing Python Dictionary in JSON File<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>customer_29876 = {\"first name\": \"David\",\"last name\": \"Elliott\",\n                 \"address\": \"4803 Wellesley St.\", }<\/strong>\n<strong>\nwith open(\"customer_29876.json\", \"w\") as f:\n  json.dump(customer_29876, f)<\/strong><\/code><\/pre>\n<\/div>\n\n\n\n<div style=\"height:50px\" aria-hidden=\"true\" class=\"wp-block-spacer\"><\/div>\n\n\n\n<div class=\"wp-block-group is-vertical is-content-justification-stretch is-layout-flex wp-container-core-group-is-layout-353c4f5a wp-block-group-is-layout-flex\">\n<h3 class=\"wp-block-heading has--font-size\">Reading Data from JSON File<\/h3>\n\n\n\n<pre class=\"wp-block-code\"><code><strong>with open(\"customer_29876.json\") as f:\n   customer_29876 = json.load(f)\n\nprint(customer_29876)\nprint(customer_29876&#91;\"last name\"])<\/strong><\/code><\/pre>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Writing Python List in JSON File Writing Python Dictionary in JSON File Reading Data from JSON File<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"wp-custom-template-python","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"","_seopress_robots_index":"","footnotes":""},"categories":[5],"tags":[],"class_list":{"0":"post-853","1":"post","2":"type-post","3":"status-publish","4":"format-standard","6":"category-python"},"_links":{"self":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts\/853","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/comments?post=853"}],"version-history":[{"count":6,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts\/853\/revisions"}],"predecessor-version":[{"id":873,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/posts\/853\/revisions\/873"}],"wp:attachment":[{"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/media?parent=853"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/categories?post=853"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/augurytech.co.uk\/courses\/wp-json\/wp\/v2\/tags?post=853"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}