Skip to content

Comments

Migrate from json to json-ng#65

Merged
SeanTAllen merged 4 commits intomainfrom
migrate-to-json-ng
Feb 14, 2026
Merged

Migrate from json to json-ng#65
SeanTAllen merged 4 commits intomainfrom
migrate-to-json-ng

Conversation

@SeanTAllen
Copy link
Member

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.

  • Parsing: JsonDoc.>parse(source)?JsonParser.parse(source) returning (JsonType | JsonParseError)
  • Field extraction: JsonExtractor(obj("key")?)JsonNav(json)("key")
  • Null handling: NoneJsonNull, 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 valJsonType val
  • Error messages: json.string()JsonTypeString(json) utility

Public API (model types, operation primitives, Promise return types) is unchanged. All 20 tests pass and all 23 examples build.

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.
@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Feb 13, 2026
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.
@SeanTAllen SeanTAllen merged commit e3d81a8 into main Feb 14, 2026
8 checks passed
@SeanTAllen SeanTAllen deleted the migrate-to-json-ng branch February 14, 2026 00:12
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Feb 14, 2026
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.

2 participants