Opened 10 years ago

Closed 10 years ago

#5630 closed defect (fixed)

valid GeoJSON web request fails to parse in QGIS 2.4 and ogr2ogr web client

Reported by: mrfnord Owned by: warmerdam
Priority: normal Milestone: 1.11.1
Component: OGR_SF Version: unspecified
Severity: normal Keywords: json utf-8 bom
Cc:

Description

Using this geojson endpoint: http://hydromartdata.trwd.com/api/spatial/sum/38/2weeksago/33.5/31.8/-98/-96

both the web client (http://ogre.adc4gis.com/) and QGIS 2.4 plugin fail with the following errors: {"error":true,"msg":"ogr2ogr failed to do the conversion"} and OGR[3] error 4: Failed to read GeoJSON data

Copying and pasting the contents of the endpoint into the web tool's textarea allows it to be parsed, but saving as text file does not fix QGIS plugin error.

I'm guessing this has something to do with either HTTP headers or with some non-visible characters, but I can't find anything unusual. The http response I get looks pretty normal: HTTP/1.1 200 OK Cache-Control: no-cache Pragma: no-cache Content-Type: text/geojson Content-Encoding: gzip Expires: -1 Vary: Accept-Encoding Server: Microsoft-IIS/7.5 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Thu, 28 Aug 2014 18:09:13 GMT Content-Length: 54032

Change History (2)

comment:1 by Jukka Rahkonen, 10 years ago

I tested by saving the file from the link on disk. Ogr2ogr from GDAL 2.0-dev gives an error

ERROR 4: Failed to read GeoJSON data ERROR 4: Failed to read GeoJSON data FAILURE: Unable to open datasource `96.json' with the following drivers

Text copy-pasted into GeoJSONLint http://geojsonlint.com/ gives no errors at all.

-Jukka Rahkonen-

comment:2 by Even Rouault, 10 years ago

Component: defaultOGR_SF
Keywords: json utf-8 bom added
Milestone: 1.11.1
Resolution: fixed
Status: newclosed

The issue was the presence of the 3 binary characters of UTF-8 BOM (Byte Order Marker). Such marker is forbidden by the current JSON spec ( http://www.ietf.org/rfc/rfc4627.txt ) at paragraph 3. Encoding "Since the first two characters of a JSON text will always be ASCII characters [RFC0020]". And the UTF-8 BOM is non ASCII. Proposed revision of JSON spec ( http://tools.ietf.org/html/rfc7159 ), 8.1. Character Encoding, is more explicit : "Implementations MUST NOT add a byte order mark to the beginning of a JSON text. In the interests of interoperability, implementations that parse JSON texts MAY ignore the presence of a byte order mark rather than treating it as an error"

trunk r27612, branches/1.11 r27613 "GeoJSON: accept and skip UTF-8 BOM (#5630)"

Note: See TracTickets for help on using tickets.