This is a static archive of our old OpenStreetMap Help Site. Please post any new questions and answers at community.osm.org.

JSONDecodeError when convert query result in jupyter notebook (python)

0

Hello,

I'm using python (jupyter notebook) to get data of hospitals in Bali area, Indonesia. Here is my code and query:

import pandas as pd
import requests
import json
overpass_api = "http://overpass-api.de/api/interpreter"

query_hospital = """
[out:json];
{{geocodeArea:'Provinsi Bali'}}->.searchArea;
node[amenity='hospital'](area.searchArea);
out;
"""

response_hospital = requests.get(overpass_api, params={'data':query_hospital})

but when I run the next code,

data_hospital = response_hospital.json()

it returns error JSONDecodeError: Expecting value: line 1 column 1 (char 0)

the query works well in Overpass Turbo but when I put in notebook, it returns error.

Thanks for the help.

asked 08 May '22, 15:05

salmiah-ls's gravatar image

salmiah-ls
11113
accept rate: 0%

edited 09 May '22, 23:43

check the status code of the query, it's returning 400. The .text says: Error: line 2: parse error: Unknown type "{", Error: line 2: parse error: An empty query is not allowed and Error: line 2: parse error: ';' expected - '{' found.

(08 May '22, 20:31) Marcos Dione

yes, I have the same thought. looks like python can't parse that double curly braces {{ }}.

I wonder if there is way to modify the query in OSM so it can return the same result but without that double curly braces.

(09 May '22, 05:53) salmiah-ls

One Answer:

0

I've found the solution.

I modify the query so I doesn't include the double curly braces {{ }} anymore, which seems python can't parse. Here is my new query:

query_hospital = """
[out:json];
area[name=Bali];
node[amenity='hospital'](area);
out;
"""

or if we use area name in local language:

query_hospital = """
[out:json];
area['name:id'='Provinsi Bali'];
node[amenity='hospital'](area);
out;
"""

the query returns same result and python can parse it now.

answered 09 May '22, 23:41

salmiah-ls's gravatar image

salmiah-ls
11113
accept rate: 0%

edited 09 May '22, 23:57

Source code available on GitHub .