Objective:
I am coming from javascript background. I am try to parse a json.
json.loads is supposed to convert stringfied values into their relevant type.
How can it be done with python 3? Purpose is eval all values with relevant type.
Scenerio: I am reading csv in python when reading csv, values are converted to strings I removed csv code becuase it was not relevant !!!
Code:
import json
x = '{ "name":"John", "age":30, "dev":"true", "trig":"1.0E-10", "res":"0.1"}'
y = json.loads(x)
print(y)
Current Output:
{
"name": "John",
"age": "30",
"dev": "true",
"trig": "1.0E-10",
"res": "0.1"
}
Expected output:
{
"name": "John",
"age": 30, // int
"dev": true, // bool
"trig": 1.0E-10, // real number
"res": 0.1 // float
}
trueand1.0E-10and0.1. That makes them strings. It would be the same if you were loading the same JSON in JavaScript.