{"id":25388,"date":"2022-12-09T21:20:58","date_gmt":"2022-12-09T15:50:58","guid":{"rendered":"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/"},"modified":"2022-12-09T21:20:58","modified_gmt":"2022-12-09T15:50:58","slug":"solved-taking-1-specific-item-out-of-json-response-using-python","status":"publish","type":"post","link":"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/","title":{"rendered":"[Solved] Taking 1 specific item out of JSON response using Python"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div id=\"answer-29677421\" class=\"answer js-answer accepted-answer js-accepted-answer\" data-answerid=\"29677421\" data-parentid=\"29674717\" data-score=\"0\" data-position-on-page=\"1\" data-highest-scored=\"1\" data-question-has-accepted-highest-score=\"1\" itemprop=\"acceptedAnswer\" itemscope itemtype=\"https:\/\/schema.org\/Answer\">\n<div class=\"post-layout\">\n<div class=\"votecell post-layout--left\"><\/div>\n<div class=\"answercell post-layout--right\">\n<div class=\"s-prose js-post-body\" itemprop=\"text\">\n<p>Consider a simplified example where your line of code<\/p>\n<pre class=\"lang-python prettyprint-override\"><code>&gt;&gt;&gt; response=conn.getresponse()\n<\/code><\/pre>\n<p>has retrieved the response from the server and saved it as an <a rel=\"nofollow noopener\" target=\"_blank\" href=\"https:\/\/docs.python.org\/3\/library\/http.client.html\">HTTPResponse object<\/a>, and when you <code>.read()<\/code> the response you see a JSON string like this<\/p>\n<pre class=\"lang-python prettyprint-override\"><code>&gt;&gt;&gt; responseData = response.read().decode('utf-8')\n&gt;&gt;&gt; responseData\n'{\"day\": \"Thursday\", \"id\": 3720348749}'\n<\/code><\/pre>\n<p>You can use Python&#8217;s built-in JSON decoder to convert that into a Dictionary object named <code>items<\/code><\/p>\n<pre class=\"lang-python prettyprint-override\"><code>&gt;&gt;&gt; import json\n&gt;&gt;&gt; items = json.loads(responseData)\n<\/code><\/pre>\n<p>Now you can extract the <code>id<\/code> value by referring to the Dictionary entry whose key is &#8216;id&#8217;<\/p>\n<pre class=\"lang-python prettyprint-override\"><code>&gt;&gt;&gt; idValue = items['id']\n&gt;&gt;&gt; print(idValue)\n3720348749\n<\/code><\/pre>\n<p>If you run the same code tomorrow and the <code>response<\/code> object that is returned contains<\/p>\n<pre class=\"lang-python prettyprint-override\"><code>&gt;&gt;&gt; responseData = response.read().decode('utf-8')\n&gt;&gt;&gt; responseData\n'{\"day\": \"Friday\", \"id\": 4567890123}'\n<\/code><\/pre>\n<p>then the same set of steps will extract the new value for <code>id<\/code><\/p>\n<pre class=\"lang-python prettyprint-override\"><code>&gt;&gt;&gt; import json\n&gt;&gt;&gt; items = json.loads(responseData)\n&gt;&gt;&gt; idValue = items['id']\n&gt;&gt;&gt; print(idValue)\n4567890123\n<\/code><\/pre>\n<p><strong>Update<\/strong><\/p>\n<p>If your actual JSON data contains nested elements then you may need to use several &#8220;key&#8221; values to identify the item you want. For example if the &#8220;id&#8221; you want to retrieve is actually<\/p>\n<pre class=\"lang-python prettyprint-override\"><code>result\n    job\n        id\n<\/code><\/pre>\n<p>i.e., the JSON looks like<\/p>\n<pre class=\"lang-python prettyprint-override\"><code>'{\"result\": {\"job\": {\"id\": 12345678}}}'\n<\/code><\/pre>\n<p>then you will need to use<\/p>\n<pre class=\"lang-python prettyprint-override\"><code>idValue = items['result']['job']['id']\n<\/code><\/pre>\n<\/p><\/div>\n<div class=\"mt24\"><\/div>\n<\/div>\n<p>            <span class=\"d-none\" itemprop=\"commentCount\">12<\/span> <\/p><\/div>\n<\/div>\n<p>[ad_2]<\/p>\n<p>solved Taking 1 specific item out of JSON response using Python <\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] Consider a simplified example where your line of code &gt;&gt;&gt; response=conn.getresponse() has retrieved the response from the server and saved it as an HTTPResponse object, and when you .read() the response you see a JSON string like this &gt;&gt;&gt; responseData = response.read().decode(&#8216;utf-8&#8217;) &gt;&gt;&gt; responseData &#8216;{&#8220;day&#8221;: &#8220;Thursday&#8221;, &#8220;id&#8221;: 3720348749}&#8217; You can use Python&#8217;s built-in JSON &#8230; <a title=\"[Solved] Taking 1 specific item out of JSON response using Python\" class=\"read-more\" href=\"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/\" aria-label=\"More on [Solved] Taking 1 specific item out of JSON response using Python\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[320],"tags":[356,349,1526],"class_list":["post-25388","post","type-post","status-publish","format-standard","hentry","category-solved","tag-json","tag-python","tag-response"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>[Solved] Taking 1 specific item out of JSON response using Python - JassWeb<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"[Solved] Taking 1 specific item out of JSON response using Python - JassWeb\" \/>\n<meta property=\"og:description\" content=\"[ad_1] Consider a simplified example where your line of code &gt;&gt;&gt; response=conn.getresponse() has retrieved the response from the server and saved it as an HTTPResponse object, and when you .read() the response you see a JSON string like this &gt;&gt;&gt; responseData = response.read().decode(&#039;utf-8&#039;) &gt;&gt;&gt; responseData &#039;{&quot;day&quot;: &quot;Thursday&quot;, &quot;id&quot;: 3720348749}&#039; You can use Python&#8217;s built-in JSON ... Read more\" \/>\n<meta property=\"og:url\" content=\"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/\" \/>\n<meta property=\"og:site_name\" content=\"JassWeb\" \/>\n<meta property=\"article:published_time\" content=\"2022-12-09T15:50:58+00:00\" \/>\n<meta name=\"author\" content=\"Kirat\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Kirat\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/\"},\"author\":{\"name\":\"Kirat\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\"},\"headline\":\"[Solved] Taking 1 specific item out of JSON response using Python\",\"datePublished\":\"2022-12-09T15:50:58+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/\"},\"wordCount\":162,\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"keywords\":[\"json\",\"python\",\"response\"],\"articleSection\":[\"Solved\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/\",\"url\":\"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/\",\"name\":\"[Solved] Taking 1 specific item out of JSON response using Python - JassWeb\",\"isPartOf\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#website\"},\"datePublished\":\"2022-12-09T15:50:58+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/jassweb.com\/solved\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"[Solved] Taking 1 specific item out of JSON response using Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/jassweb.com\/solved\/#website\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"name\":\"JassWeb\",\"description\":\"Build High-quality Websites\",\"publisher\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/jassweb.com\/solved\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/jassweb.com\/solved\/#organization\",\"name\":\"Jass Web\",\"url\":\"https:\/\/jassweb.com\/solved\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"contentUrl\":\"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png\",\"width\":693,\"height\":132,\"caption\":\"Jass Web\"},\"image\":{\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31\",\"name\":\"Kirat\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"contentUrl\":\"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939\",\"caption\":\"Kirat\"},\"sameAs\":[\"http:\/\/jassweb.com\"],\"url\":\"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"[Solved] Taking 1 specific item out of JSON response using Python - JassWeb","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:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/","og_locale":"en_US","og_type":"article","og_title":"[Solved] Taking 1 specific item out of JSON response using Python - JassWeb","og_description":"[ad_1] Consider a simplified example where your line of code &gt;&gt;&gt; response=conn.getresponse() has retrieved the response from the server and saved it as an HTTPResponse object, and when you .read() the response you see a JSON string like this &gt;&gt;&gt; responseData = response.read().decode('utf-8') &gt;&gt;&gt; responseData '{\"day\": \"Thursday\", \"id\": 3720348749}' You can use Python&#8217;s built-in JSON ... Read more","og_url":"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/","og_site_name":"JassWeb","article_published_time":"2022-12-09T15:50:58+00:00","author":"Kirat","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Kirat","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/#article","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/"},"author":{"name":"Kirat","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31"},"headline":"[Solved] Taking 1 specific item out of JSON response using Python","datePublished":"2022-12-09T15:50:58+00:00","mainEntityOfPage":{"@id":"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/"},"wordCount":162,"publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"keywords":["json","python","response"],"articleSection":["Solved"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/","url":"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/","name":"[Solved] Taking 1 specific item out of JSON response using Python - JassWeb","isPartOf":{"@id":"https:\/\/jassweb.com\/solved\/#website"},"datePublished":"2022-12-09T15:50:58+00:00","breadcrumb":{"@id":"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/jassweb.com\/solved\/solved-taking-1-specific-item-out-of-json-response-using-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/jassweb.com\/solved\/"},{"@type":"ListItem","position":2,"name":"[Solved] Taking 1 specific item out of JSON response using Python"}]},{"@type":"WebSite","@id":"https:\/\/jassweb.com\/solved\/#website","url":"https:\/\/jassweb.com\/solved\/","name":"JassWeb","description":"Build High-quality Websites","publisher":{"@id":"https:\/\/jassweb.com\/solved\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/jassweb.com\/solved\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/jassweb.com\/solved\/#organization","name":"Jass Web","url":"https:\/\/jassweb.com\/solved\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/","url":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","contentUrl":"https:\/\/jassweb.com\/wp-content\/uploads\/2021\/02\/jass-website-logo-1.png","width":693,"height":132,"caption":"Jass Web"},"image":{"@id":"https:\/\/jassweb.com\/solved\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/65c9c7b7958150c0dc8371fa35dd7c31","name":"Kirat","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/jassweb.com\/solved\/#\/schema\/person\/image\/","url":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","contentUrl":"https:\/\/jassweb.com\/solved\/wp-content\/litespeed\/avatar\/1261af3c9451399fa1336d28b98ea3bb.jpg?ver=1775193939","caption":"Kirat"},"sameAs":["http:\/\/jassweb.com"],"url":"https:\/\/jassweb.com\/solved\/author\/jaspritsinghghumangmail-com\/"}]}},"_links":{"self":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/25388","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/comments?post=25388"}],"version-history":[{"count":0,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/posts\/25388\/revisions"}],"wp:attachment":[{"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/media?parent=25388"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/categories?post=25388"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jassweb.com\/solved\/wp-json\/wp\/v2\/tags?post=25388"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}