#35989 closed Bug (fixed)

GeoJSON serializer producing invalid output (crs attribute)

Reported by: Jeremy Thompson Owned by: Jeremy Thompson
Component: GIS Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Jeremy Thompson)

The built-in GeoJSON serializer is producing invalid GeoJSON. The serialized output has a section like:

"crs": {"type": "name", "properties": {"name": "EPSG:4326"}}

However, according to the GeoJSON spec the crs attribute was removed from the spec in August of 2016 (ref: ​https://datatracker.ietf.org/doc/html/rfc7946#appendix-B.1)

This is causing issues when trying to use GeoJSON as the intermediary data format for passing data to other libraries (e.g. Leaflet ​https://leafletjs.com considers GeoJSON with the crs attribute as invalid and fails to parse it).

More information in the forum discussion here: ​https://forum.djangoproject.com/t/geojson-serializer-producing-invalid-output-crs/37097

Change History (11)

comment:1 by Jeremy Thompson, 23 months ago

Type: Uncategorized → Bug

comment:2 by Jeremy Thompson, 23 months ago

Description: modified (diff)

comment:3 by Jeremy Thompson, 23 months ago

Owner: set to Jeremy Thompson
Status: new → assigned

comment:4 by Claude Paroz, 23 months ago

Triage Stage: Unreviewed → Accepted
Version: 5.1 → dev

Many thanks for noticing!

comment:5 by Jeremy Thompson, 23 months ago

Has patch: set

comment:6 by Jeremy Thompson, 23 months ago

After a bit more investigation, I think my initial problem with Leaflet was due to how I was using the json_script filter. I was passing the string that was output from the serializer, which meant that the double quotes were getting escaped, which led to invalid JSON. When I created a Python dict with the same information, things worked as expected.

I think this issue still might be relevant though? But not for my original reason.

Last edited 23 months ago by Jeremy Thompson (previous) (diff)

comment:7 by Claude Paroz, 23 months ago

Thanks for the update. Yes, this change still makes sense, however with lesser priority.

comment:8 by Sarah Boyce, 23 months ago

Patch needs improvement: set

comment:9 by Jeremy Thompson, 23 months ago

Patch needs improvement: unset

Comments in PR addressed!

comment:10 by Claude Paroz, 23 months ago

Triage Stage: Accepted → Ready for checkin

comment:11 by Sarah Boyce <42296566+sarahboyce@…>, 23 months ago

Resolution: → fixed
Status: assigned → closed

In 918e7a2:

Fixed #35989 -- Removed crs from GeoJSON serializer.

Specification of coordinate reference systems (crs) was removed from the GeoJSON spec in 2016.
​https://datatracker.ietf.org/doc/html/rfc7946#appendix-B.1

Note: See TracTickets for help on using tickets.
Back to Top