

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python - Ways to convert string to json object
Data send and get generally in a string of dictionary(JSON objects) forms in many web API’s to use that data to extract meaningful information we need to convert that data in dictionary form and use for further operations.
Example
# converting string to json # using json.loads import json # inititialising json object ini_string = {'vishesh': 1, 'ram' : 5, 'prashant' : 10, 'vishal' : 15} # printing initial json ini_string = json.dumps(ini_string) print ("initial 1st dictionary", ini_string) print ("type of ini_object", type(ini_string)) # converting string to json final_dictionary = json.loads(ini_string) # printing final result print ("final dictionary", str(final_dictionary)) print ("type of final_dictionary", type(final_dictionary))
Output
('initial 1st dictionary', '{"vishal": 15, "ram": 5, "vishesh": 1, "prashant": 10}') ('type of ini_object', <type 'str'>) ('final dictionary', "{u'vishal': 15, u'ram': 5, u'vishesh': 1, u'prashant': 10}") ('type of final_dictionary', <type 'dict'>)
- Related Questions & Answers
- How to convert string to JSON using Python?
- How to convert JSON text to JavaScript JSON object?
- How can we convert a JSON string to a JSON object in Java?
- How to convert a JSON string into a JavaScript object?
- How to convert JSON data into a Python object?
- Convert a JSON String to Java Object using the json-simple library in Java?
- Convert Java String Object to Boolean Object
- Convert JSON object to Java object using Gson library in Java?
- How to convert Java object to JSON using GSON library?
- How to convert Java object to JSON using Jackson library?
- How to convert JSON object to Hashtable format using PowerShell?
- Convert a JSON object to XML format in Java?
- Strip quotes with JavaScript to convert into JSON object?
- How to convert a Map to JSON object using JSON-lib API in Java?
- How to convert timestamp string to datetime object in Python?
Advertisements