Issues when using JSON.dumps on an array

Viewed 15

I'm creating a payload to send as body on an POST request. I Try to add some floats to a list within a dict. When the values are static everything is ok, but when I add the floats within the list as variable. json.dumps() convert them to a string.

Example with static values

 payload = json.dumps({
        "_geo": {
            "intersects": {
                "type": "Point",
                "coordinates": [
                    4.895168,
                    52.370216
                ]
            }
        }
    })

    print(payload)

print result:

{"_geo": {"intersects": {"type": "Point", "coordinates": [4.895168, 52.370216]}}}

Example with variables


 latitude = 4.895168
 longitude = 52.370216

 payload = json.dumps({
        "_geo": {
            "intersects": {
                "type": "Point",
                "coordinates": [
                    latitude,
                    longitude
                ]
            }
        }
    })

print result

{"_geo": {"intersects": {"type": "Point", "coordinates": ["4.895168", "52.370216"]}}}

The problem

As you can see when using variables, the floats are converted to strings. How can I make the result the same as with static values?

0 Answers
Related