{"id":26857,"date":"2022-03-31T02:19:23","date_gmt":"2022-03-30T20:49:23","guid":{"rendered":"https:\/\/python-programs.com\/?p=26857"},"modified":"2022-03-31T02:19:23","modified_gmt":"2022-03-30T20:49:23","slug":"how-to-extract-a-single-value-from-json-response-using-api-call-in-python","status":"publish","type":"post","link":"https:\/\/python-programs.com\/how-to-extract-a-single-value-from-json-response-using-api-call-in-python\/","title":{"rendered":"How to Extract a Single Value from JSON Response Using API Call in Python?"},"content":{"rendered":"

In this Python article, let us look at how to use Python to obtain single data or single values from JSON. To complete this task, we will use Python’s request module, which allows users to send HTTP requests and get responses in the form of JSON.<\/p>\n

What is JSON?<\/strong><\/p>\n

JSON is an abbreviation for JavaScript Object Notation. It means that data is stored and transferred using a script (executable) file comprised of text in a computer language. Python has a built-in library named json that handles JSON. In order to use this feature, we must first load the json package into our Python script. The text in JSON is represented by a quoted-string, which contains the value in the key-value mapping within flower braces { }.<\/p>\n

Example:<\/strong><\/p>\n

{\r\n  \u00a0 \"data\": [\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \"ID\": \"1\",\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \"NAME\": \"Dhoni\",\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \"SALARY\": \"100000\"\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0},\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0{\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \"ID\": \"2\",\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \"NAME\": \u201cVirat\u201d,\r\n  \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \"SALARY\": \"90000\"\r\n \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0}\r\n  \u00a0 \u00a0]\r\n}<\/pre>\n
\n
Get the API Key from the URL:<\/strong><\/div>\n
https:\/\/exchangeratesapi.io\/documentation\/<\/a><\/div>\n
<\/div>\n<\/div>\n

Extracting a Single Value from JSON Response Using API Call in Python<\/h2>\n

Approach:<\/strong><\/p>\n