Reputation: 886
I have a simple python code that returns a JSON object with one boolean fields and two others. The goal is to get the following response
{
"prop": "foo",
"name": "bar",
"isSomething": true
}
I need a valid JSON true
, but the python response gives me a JSON string "true"
.
{
"prop": "foo",
"name": "bar",
"isSomething": "true"
}
My Python code is:
import json
x = {
'prop' : 'foo',
'name': 'bar',
'isSomething': json.dumps(True)
}
return x
I am executing this code using Python 3.7.
Upvotes: 0
Views: 897
Reputation: 33521
You should json.dumps
the entire x
object:
import json
x = {
'prop' : 'foo',
'name': 'bar',
'isSomething': True
}
return json.dumps(x)
Upvotes: 3