Skip to content

json module: expand with path access and helpers via vendored cJSON #1451

@SchoolyB

Description

@SchoolyB

Context

The json module currently exposes only encode, decode, pretty_print, is_valid. That is barely enough to be useful — users cannot pull a nested value out of a decoded object without verbose manual traversal.

A dedicated JsonValue tagged union was considered and rejected for now. Stay with generic maps.

Approach

Vendor cJSON (small, permissive, C) under ezc/vendor/cjson/. Same pattern as sqlite.

Additions

  • get(obj, "path.to.key") — dotted path accessor, returns value or null
  • has(obj, "path.to.key") — existence check
  • set(obj, "path.to.key", value) — set value at path, creating intermediate objects as needed
  • remove(obj, "path.to.key") — delete a key at path
  • keys(obj) — top-level keys
  • type_of(value) — return "null" / "bool" / "number" / "string" / "array" / "object"

Out of scope

  • Streaming decode
  • Schema validation
  • Typed unmarshaling into structs (revisit in 3.1)

Target

3.0 GA

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requeststdlibGeneral standard library issues

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions