Reputation: 469
I'm new to JSON. I have a dictionary, I convert it to a JSON object using
myJsonObject = json.dumps(myDictionary)
But then If I check the type, I get <type 'str'>
Is string is the expected output for a JSON object?
PS: Python 2.7
Update: How can I get a JSON type, if dumps is not the correct way?
Upvotes: 27
Views: 51005
Reputation: 1512
The N of JSON is for Notation ; it is, indeed, a data format specification. A JSON object is usually intended to be used as a storage or inter-process communication format. That's why it is in Python the universal flat format accepted by write() : a string object.
You can print it to screen, save it to a file, or communicate it to another program to verify it is correct and containing expected data.
Upvotes: 5
Reputation: 473863
Of course, this is called "Serialization" - you are dumping a Python data structure into a JSON formatted string:
json.dumps()
Serialize obj to a JSON formatted str using this conversion table.
If you load a JSON string with loads()
, this would be "deserialization" and you would get a Python list or a dictionary.
Upvotes: 24