fix: serialize array-valued GeoJSON properties as JSON#1348
Open
chuenchen309 wants to merge 1 commit into
Open
fix: serialize array-valued GeoJSON properties as JSON#1348chuenchen309 wants to merge 1 commit into
chuenchen309 wants to merge 1 commit into
Conversation
geojson2csv only ran json.dumps on OrderedDict property values, so an array (list) property fell through to the CSV writer's str() and was emitted as a Python repr — e.g. ['park', 'landmark'], which is not valid JSON and not round-trippable. An object property in the same row was already emitted as JSON, so the two container types diverged. This completes the intent of the existing OrderedDict json.dumps (added per the "prints a JSON object instead of OrderedDict([(...)])" changelog entry): dump lists as well.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
in2csv --format geojsonserializes an object-valued GeoJSON property as JSON, but an array-valued property is emitted as a Pythonrepr— invalid, non-round-trippable JSON. Both container types appear side by side in the same row:categories(array) →['park', 'landmark']— Python repr, single quotes, not valid JSONopening_hours(object) →{"mon": "6-1"}— JSONPer GeoJSON (RFC 7946), a Feature's
propertiesis a JSON object whose values may be arrays (tags, categories, times…), so array-valued properties are ordinary input.Root cause
csvkit/convert/geojs.py:That
OrderedDictcheck was added specifically to stop emitting Python repr (CHANGELOG: "in2csv with--format geojsonprints a JSON object instead ofOrderedDict([(...)])"). Arrays are the other half of the same intent and were left out.The fix
Verification
["park", "landmark"]; the object column is unchanged.test_geojson_array_propertytotests/test_utilities/test_in2csv.py; it fails onmaster(the cell is the repr) and passes with the fix.tests/test_convert/+tests/test_utilities/test_in2csv.py→ 68 passed.flake8/isortclean. CHANGELOG entry added.Not a duplicate — no open issue/PR touches geojson input conversion (the nearby closed #827 was about
csvjsonoutput, the opposite direction).This PR was authored by an AI coding agent (Claude Code) running on this account: the AI found the bug, ran the repro, wrote the test, and wrote this description. The human account holder reviews every change and is accountable for it. The verification above is real and re-runnable from the diff. If this isn't the kind of contribution you want, say so and I'll close it.