Skip to content

Migrate to JSON.jl v1 from JSON3.jl - #127

Open
simsurace wants to merge 19 commits into
JuliaGeo:mainfrom
simsurace:json-v1
Open

simsurace wants to merge 19 commits into
JuliaGeo:mainfrom
simsurace:json-v1

Conversation

@simsurace

Copy link
Copy Markdown

JSON3.jl is deprecated, so this should probably be done sooner rather than later.
This bumps the version to 0.9 to be on the safe side because some serialization details may change here.

asinghvi17 and others added 19 commits December 7, 2025 15:54
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Replace StructTypes.CustomStruct/lower/lowertype with StructUtils.lower for GeoJSONWrapper
- Replace StructTypes.AbstractType/subtypekey/subtypes with JSON.@choosetype macro
- Add _choose_geometry_type and _choose_geojson_type functions for polymorphic parsing
- Replace StructTypes.excludes with StructUtils.@exclude for FeatureCollection
- Remove StructTypes.omitempties (now handled at call site with omit_null=true)
- Remove redundant StructType declarations for concrete types (default struct behavior)

This completes Task 6 of the JSON3 to JSON.jl migration.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit completes the migration by implementing custom StructUtils.make
and StructUtils.lift methods to replace JSON3's @choosetype macro functionality.

Key changes:
- Implemented custom type choosers for AbstractGeometry and GeoJSONT
- Added StructUtils.lift method for handling JSON.Object conversion
- Updated GeoJSONWrapper with manual type selection logic
- Fixed FeatureCollection field types to handle JSON parsing edge cases
- Improved write() methods to return nothing for IO operations
- Enhanced read() to handle both file paths and JSON strings
- Added helper functions for coordinate type conversion

All tests passing (234/234).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Capture each feature's raw JSON via JSON's JSONText span finder and
re-parse on access, and write lazy features and collections back out
verbatim.
JSON downgrades to the inner DefaultStyle before calling lift, so match
DefaultStyle exactly: the method is reached at runtime and no longer
overlaps JSON's JSONReadStyle lift that Aqua flagged.
The active lowering splatted every struct field, so FeatureCollections
emitted their internal name/type cache and features wrote absent id,
bbox and crs members as null. Prune the computed fields and omit the
empty optional members (matching the old omitempties), and remove the
dead single-argument lowerings that JSON never dispatched to.
Reading 3D data without ndim=3 silently dropped the Z coordinate:
NTuple and StructUtils both truncate an over-long array rather than
erroring, so read's 2D->3D fallback never triggered. Route both the
lazy make path and the materialized lift path through one strict
builder that rejects a wrong-dimension coordinate, restoring the
fallback and collapsing the two duplicated construction paths into one.

Also clarify why the type choosers can't use @choosetype.
Its abstract branch duplicated the GeoJSONWrapper chooser and its
concrete branch just re-invoked the default struct parse, so removing
it changes nothing — the full suite still passes.
Swapping JSON3/StructTypes for JSON.jl/StructUtils changes dependencies
and serialization details, so bump the minor version rather than the
patch to signal the break.
@juliohm

juliohm commented Sep 10, 2026

Copy link
Copy Markdown
Member

Thank you @simsurace. Any update here?

JSON3.jl now shows a [deprecated] warning in Pkg.jl in Julia v1.13.

@simsurace

Copy link
Copy Markdown
Author

I'm waiting for someone to review this PR.

@asinghvi17

Copy link
Copy Markdown
Member

So this approach seems to tank performance quite a bit, probably an issue in my initial implementation. Will probably give it a shot from scratch sometime next week.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants