query-overpass icon indicating copy to clipboard operation
query-overpass copied to clipboard

JSON.parse error on webpack

Open Semigradsky opened this issue 7 years ago • 9 comments

I'm getting JSON.parse error because overpass is returning result in content-type: "application/osm3s+xml" https://github.com/perliedman/query-overpass/blob/7bde46af36a56d0af4b8def0d5fb892138c40c7f/index.js#L69

Semigradsky avatar Jan 28 '18 16:01 Semigradsky

Fixed by adding '[out:json];' in query

Semigradsky avatar Jan 28 '18 16:01 Semigradsky

@Semigradsky Hi can you give an example of how do you add '[out:json];' . I got the same parse error, but with this I still receive the same parser error:

query_overpass('way(57.7,11.9,57.701,11.901)[out=json];out;', writeToHTML);

boxin-nutonomy avatar Jan 29 '18 06:01 boxin-nutonomy

try query_overpass('[out:json];way(57.7,11.9,57.701,11.901);out;', writeToHTML);

tyrasd avatar Jan 29 '18 09:01 tyrasd

I'm a little at loss of what the issue is here. If you could provide an example that reproduces this problem, it might be possible to debug.

I've tried @boxin-nutonomy's example from the command line without issue:

$ echo 'way(57.7,11.9,57.701,11.901);out;'| query-overpass
{"type":"FeatureCollection","features":[]}

perliedman avatar Jan 29 '18 09:01 perliedman

@perliedman you will get this error if remove [out:json]; here: https://github.com/Semigradsky/osm-validator/blob/af94db85a77e0786009bf29c3ff38d4ea0b7e7bb/src/main.js#L38

Just run

npm install
npm run build

open index.html in browser and press button.

Semigradsky avatar Jan 29 '18 10:01 Semigradsky

@tyrasd It works! Thank you for the help:)))) @perliedman I have tried to run from command line and javascript. For command line, echo 'way(57.7,11.9,57.8,12.0);out;' | query-overpass does not produce any errors. However, if you run query_overpass('way(57.7,11.9,57.8,12.0);out;', writeToHTML); in javascript, there is error in console log. Please try the javascript library to reproduce the error.

boxin-nutonomy avatar Jan 30 '18 02:01 boxin-nutonomy

@Semigradsky hm, guessing you changed something, doing those steps works for me (displays a number of markers on the map)...

perliedman avatar Jan 30 '18 09:01 perliedman

@perliedman sorry I didn't right specify the sequence of actions. Need remove [out:json]; and run npm run build after this.

Semigradsky avatar Jan 30 '18 13:01 Semigradsky

Looking at this again, it is clear that the issue is that query-overpass in the browser can only handle JSON, not XML.

This should be documented. Possibly, it would also be interesting to add XML support on the browser as well.

perliedman avatar Sep 07 '19 09:09 perliedman