How to parse data in JSON format

How to parse data in JSON format

Hi,

I want to parse following json string in Python and get values from it.

user = {"user":"testuser", "password":"testpass", "isactive":"Yes"}

How to parse data in JSON format?

Thanks

View Answers

July 18, 2021 at 7:14 PM

Hi,

For parsing string into json object you can use the json library of Python.

First of import json:

import json

After that you can parse your json string with json.loads() function. Here is the complete code:

import json

user = '{"user":"testuser", "password":"testpass", "isactive":"Yes"}'

jsonObj = json.loads(user)

user=jsonObj["user"]
password=jsonObj["password"]
isactive=jsonObj["isactive"]

print(user)
print(password)
print(isactive)

Output of the program:

>>> import json
>>> 
>>> user = '{"user":"testuser", "password":"testpass", "isactive":"Yes"}'
>>> 
>>> jsonObj = json.loads(user)
>>> 
>>> user=jsonObj["user"]
>>> password=jsonObj["password"]
>>> isactive=jsonObj["isactive"]
>>> 
>>> print(user)
testuser
>>> print(password)
testpass
>>> print(isactive)
Yes
>>>

So, I showed you how to parse data in JSON object in Python and after that get the json values.

Thanks


July 18, 2021 at 7:14 PM

Hi,

Check more tutorials at:

Thanks

Ads









Related Tutorials/Questions & Answers:
How to parse data in JSON format
How to parse data in JSON format  Hi, I want to parse following json string in Python and get values from it. user = {"user":"testuser", "password":"testpass", "isactive":"Yes"} How to parse data in JSON format? Thanks
how to parse json in python and get data
how to parse json in python and get data  Hi, I have to parse... library to parse the data and get the value. Thanks   Hi, You can use... you have to parse the json and then get it using your key name. Thanks
Advertisements
How to format json String in Java
How to format json String in Java  Hi, How to format json String in Java? I have an object of HashMap how to convert it to formatted output... library. Then use following method to covert it to JSON String: String json
How to format json String in Java
How to format json String in Java  Hi, How to format json String in Java? I have an object of HashMap how to convert it to formatted output... library. Then use following method to covert it to JSON String: String json
socket connection: how to parse data from server?
socket connection: how to parse data from server?  hi, I am a j2me programmer,i want to retrieve some data from server using socket connection,I h'v... with inputstream read() method. Now I want to know, how to parse the data from
convert data format sql
convert data format sql  convert data format sql
Version of ca.fuzzlesoft>json-parse dependency
List of Version of ca.fuzzlesoft>json-parse dependency
ModuleNotFoundError: No module named 'json_log_parse'
named 'json_log_parse' How to remove the ModuleNotFoundError: No module named 'json_log_parse' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'json_log_parse'  Hi, My
ModuleNotFoundError: No module named 'json-format'
'json-format' How to remove the ModuleNotFoundError: No module named 'json-format' error? Thanks   Hi, In your python environment...ModuleNotFoundError: No module named 'json-format'  Hi, My Python
How to save data to excel with a 2.1 work sheet format without changing it?
How to save data to excel with a 2.1 work sheet format without changing it?  hi , i have done a program that allows user to inout data through jtable and save it to excel file then read it again .. the problem is , when data
how to append data to XML file in proper format using JSP
how to append data to XML file in proper format using JSP  hello i was appending my XML file to add more data entered by user in JSP page.But... data entered bt more users in proper XML format. I have also tried following
PHP search data with different format
PHP search data with different format  How to search data with different format in PHP
database data in xml format
database data in xml format  HI, i want to display the database data in the xml format(not as xml file ) on the console using DOM. help will be appreciated. THANKS K.K
parse data from a link in java
parse data from a link in java  Hi, Here I want code for Extracting data from a link and the data a must be stored in mysql and then I need to display the data in a jsp page
ModuleNotFoundError: No module named 'oem-format-json'
named 'oem-format-json' How to remove the ModuleNotFoundError: No module named 'oem-format-json' error? Thanks   Hi, In your python...ModuleNotFoundError: No module named 'oem-format-json'  Hi, My
ModuleNotFoundError: No module named 'oem-format-minimize-json'
: No module named 'oem-format-minimize-json' How to remove the ModuleNotFoundError: No module named 'oem-format-minimize-json' error? Thanks  ...ModuleNotFoundError: No module named 'oem-format-minimize-json'  Hi
ModuleNotFoundError: No module named 'pretty-format-json'
named 'pretty-format-json' How to remove the ModuleNotFoundError: No module named 'pretty-format-json' error? Thanks   Hi, In your...ModuleNotFoundError: No module named 'pretty-format-json'  Hi, My
How can I get specific data from JSON
How can I get specific data from JSON  Hi, How can I get specific data from JSON? Thanks   Hi, In Python you can use the json library to parse json string. After parsing the json string into JSON object you can get
Parsing the Time Using a Custom Format
Parsing the Time Using a Custom Format In this section, you will learn how to parse the time using custom format. In the previous section, we have discussed... to specify the format of the time to parse. Then we have invoked the method parse
Maven Dependency json-parse >> 1.3.3
You should include the dependency code given in this page to add Maven Dependency of ca.fuzzlesoft >> json-parse version1.3.3 in your project
Maven Dependency json-parse >> 1.0.0
You should include the dependency code given in this page to add Maven Dependency of ca.fuzzlesoft >> json-parse version1.0.0 in your project
Maven Dependency json-parse >> 1.1.0
You should include the dependency code given in this page to add Maven Dependency of ca.fuzzlesoft >> json-parse version1.1.0 in your project
Maven Dependency json-parse >> 1.0.3
You should include the dependency code given in this page to add Maven Dependency of ca.fuzzlesoft >> json-parse version1.0.3 in your project
Maven Dependency json-parse >> 1.3.0
You should include the dependency code given in this page to add Maven Dependency of ca.fuzzlesoft >> json-parse version1.3.0 in your project
Maven Dependency json-parse >> 1.2.0
You should include the dependency code given in this page to add Maven Dependency of ca.fuzzlesoft >> json-parse version1.2.0 in your project
Maven Dependency json-parse >> 1.3.2
You should include the dependency code given in this page to add Maven Dependency of ca.fuzzlesoft >> json-parse version1.3.2 in your project
Maven Dependency json-parse >> 1.0.1
You should include the dependency code given in this page to add Maven Dependency of ca.fuzzlesoft >> json-parse version1.0.1 in your project
Maven Dependency json-parse >> 1.0.2
You should include the dependency code given in this page to add Maven Dependency of ca.fuzzlesoft >> json-parse version1.0.2 in your project
Maven Dependency json-parse >> 1.3.1
You should include the dependency code given in this page to add Maven Dependency of ca.fuzzlesoft >> json-parse version1.3.1 in your project
How to print this Format exactly?
How to print this Format exactly?   * * * & reverse
How can I get specific data from JSON
How can I get specific data from JSON  Hi, How can I get specific data from JSON? Thanks

Ads