Conversation
Replace ponylang/json with ponylang/json-ng for JSON handling.
json-ng provides a cleaner API: JsonParser.parse() returns errors as
data instead of exceptions, JsonNav chains field navigation without
intermediate Map lookups, and JsonObject uses immutable persistent
collections with .update() chaining instead of mutable Map + from_map.
Key changes:
- Parsing: JsonDoc.>parse(source)? → JsonParser.parse(source) returning
(JsonType | JsonParseError)
- Field extraction: JsonExtractor(obj("key")?) → JsonNav(json)("key")
- Null handling: None → JsonNull, with JsonNavUtil.string_or_none()
utility for the 10 nullable string field call sites
- JSON construction: mutable Map + JsonObject.from_map() → immutable
JsonObject.update() chaining
- ResultReceiver signatures: JsonDoc val → JsonType val
- Error messages: json.string() → JsonTypeString(json) utility
Public API (model types, operation primitives, Promise return types)
is unchanged.
Every converter was wrapping its JsonType parameter in JsonNav as its
first line, and converters with sub-converter calls were unwrapping
back to JsonObject just to pass JsonType to the sub-converter which
re-wrapped it. This round-trip is unnecessary since JsonNav is class
val (immutable, shareable).
Move the JsonNav wrapping to the three receiver boundaries where
JsonType arrives from HTTP handlers. Converters now receive JsonNav
directly, and sub-converter calls use nav("key") instead of
obj("key")?. This eliminates all as_object() calls and the obj
intermediate variable from every converter.
The receiver actors were wrapping JsonType in JsonNav before passing to converters. This wrapping belongs in the HTTP handlers where JsonParser.parse produces JsonType — the earliest point after parsing. Now JsonNav flows from handler to receiver to converter with no intermediate JsonType. JsonTypeString also takes JsonNav instead of JsonType since all callers now have JsonNav.
The type already communicates that the value is a JsonNav — naming the variable json makes the code read more naturally since the data IS json.
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.
Replace ponylang/json with ponylang/json-ng for JSON handling.
json-ng provides a cleaner API:
JsonParser.parse()returns errors as data instead of exceptions,JsonNavchains field navigation without intermediate Map lookups, andJsonObjectuses immutable persistent collections with.update()chaining instead of mutable Map +from_map.JsonDoc.>parse(source)?→JsonParser.parse(source)returning(JsonType | JsonParseError)JsonExtractor(obj("key")?)→JsonNav(json)("key")None→JsonNull, withJsonNavUtil.string_or_none()utility for the 10 nullable string field call sitesJsonObject.from_map()→ immutableJsonObject.update()chainingResultReceiversignatures:JsonDoc val→JsonType valjson.string()→JsonTypeString(json)utilityPublic API (model types, operation primitives, Promise return types) is unchanged. All 20 tests pass and all 23 examples build.