jazzband / geojson

Python bindings and utilities for GeoJSON
https://pypi.python.org/pypi/geojson/
BSD 3-Clause "New" or "Revised" License
913 stars 121 forks source link

Allow NULL properties on GeoJSON features #179

Closed vijaynallagatla closed 2 years ago

vijaynallagatla commented 2 years ago

geojson allows "properties": { } but not "properties": null

The GeoJSON spec says NULL is valid.

rayrrr commented 2 years ago

@vijaynallagatla thanks for reporting this issue, but I was unable to reproduce it. However, mixing Python None and JSON null in a string will result in an error. Can you confirm or deny this was your case? If you believe there is still a bug regarding this, please post some example code which demonstrates the bug and we can re-open this issue.

import geojson 

# JSON string representation of feature with Python `None` mistakenly put as value of `properties`
feature1 = '{"geometry": {"coordinates": [-3.68, 40.41], "type": "Point"}, "properties": None, "type": "Feature"}'

# JSON string representation of feature with empty JSON object as value of `properties`
feature2 = '{"geometry": {"coordinates": [-3.68, 40.41], "type": "Point"}, "properties": {}, "type": "Feature"}'

# JSON string representation of feature with JSON null as value of `properties
feature3 = '{"geometry": {"coordinates": [-3.68, 40.41], "type": "Point"}, "properties": null, "type": "Feature"}'

geojson.loads(feature1)  # failure
geojson.loads(feature2)  # success
geojson.loads(feature3)  # success
vijaynallagatla commented 2 years ago

@rayrrr thank you for looking into this issue. Basically we're using the validation from geojson lib and when we pass the JSON string rep as "properties": null we're hitting an error. Which should be supported according to the GeoJSON spec. We're using this from a Golang service and validators in golang is compatible with it "properties": null.

rayrrr commented 2 years ago

@vijaynallagatla we want to make sure this works and reflects the GeoJSON RFC in every way. As I said before, can you please give a code snippet example of the particular thing that's erroring out for you? If you can provide a code snippet showing the problem and I can reproduce it locally, we'll re-open this issue.