{"id":186,"date":"2025-08-28T14:45:27","date_gmt":"2025-08-28T14:45:27","guid":{"rendered":"https:\/\/learn.rantissi.my.id\/?p=186"},"modified":"2025-08-28T14:45:28","modified_gmt":"2025-08-28T14:45:28","slug":"manipulasi-file-json-di-python","status":"publish","type":"post","link":"https:\/\/learn.rantissi.my.id\/index.php\/2025\/08\/28\/manipulasi-file-json-di-python\/","title":{"rendered":"Manipulasi File JSON di Python"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">Apa itu JSON?<\/h2>\n\n\n\n<p>JSON (JavaScript Object Notation) = format penyimpanan data yang ringan &amp; mudah dibaca.<\/p>\n\n\n\n<p>Mirip dictionary Python:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>{\n  \"nama\": \"Ran\",\n  \"umur\": 20,\n  \"hobi\": &#91;\"ngoding\", \"makan\", \"tidur\"]\n}\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Konversi JSON &lt;=> Python<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import json\n\n# Python -&gt; JSON\ndata = {\"nama\": \"Ran\", \"umur\": 20}\nwith open(\"data.json\", \"w\") as file:\n    json.dump(data, file, indent=4)\n\n# JSON -&gt; Python\nwith open(\"data.json\", \"r\") as file:\n    hasil = json.load(file)\n    print(hasil&#91;\"nama\"])\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">Contoh Data List of Dictionary:<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>mahasiswa = &#91;\n    {\"nama\": \"Ran\", \"nim\": \"123\", \"prodi\": \"Informatika\"},\n    {\"nama\": \"Ali\", \"nim\": \"124\", \"prodi\": \"Sistem Informasi\"}\n]\n\n# Simpan ke JSON\nwith open(\"mahasiswa.json\", \"w\") as file:\n    json.dump(mahasiswa, file, indent=4)\n\n# Baca lagi dan tampilkan\nwith open(\"mahasiswa.json\", \"r\") as file:\n    daftar = json.load(file)\n    for m in daftar:\n        print(m&#91;\"nama\"], \"-\", m&#91;\"prodi\"])<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Apa itu JSON? JSON (JavaScript Object Notation) = format penyimpanan data yang ringan &amp; mudah dibaca. Mirip dictionary Python: Konversi JSON &lt;=> Python Contoh Data List of Dictionary:<\/p>\n","protected":false},"author":1,"featured_media":20,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6,7],"tags":[],"class_list":["post-186","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming","category-python"],"_links":{"self":[{"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/posts\/186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/comments?post=186"}],"version-history":[{"count":1,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/posts\/186\/revisions"}],"predecessor-version":[{"id":187,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/posts\/186\/revisions\/187"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/media\/20"}],"wp:attachment":[{"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/media?parent=186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/categories?post=186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/learn.rantissi.my.id\/index.php\/wp-json\/wp\/v2\/tags?post=186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}