Skip to content

Add a JSON parser example - #185

Merged
Rigidity merged 1 commit into
mainfrom
t3/json-example
Oct 24, 2026
Merged

Rigidity merged 1 commit into
mainfrom
t3/json-example

Conversation

@Rigidity

@Rigidity Rigidity commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator

Adds examples/json.rue, a JSON parser and serializer written in Rue, and links it from the README.

  • Each kind of JSON value is a struct with a constant kind field, so a Json value can be narrowed with is.
  • The parser handles every JSON escape, including \uXXXX with surrogate pairs (encoded as UTF-8). It also enforces JSON's rules on whitespace, leading zeros and control characters, and calls raise with a message when the input is malformed.
  • stringify writes the value back as compact JSON, and get looks up keys in objects.
  • Numbers must be integers, since CLVM has no fractions.

Rue string literals have no escape sequences, so the tests write JSON with single quotes and a json() helper swaps them for double quotes.

I also ran 13 malformed inputs through temporary tests (not committed), and each one failed with the expected error.


Note

Low Risk
Documentation and example-only changes with snapshot YAML; no compiler, stdlib, or production puzzle logic is modified.

Overview
Adds examples/json.rue, a Rue example that parses JSON into tagged structs, serializes back to compact JSON, and exposes get for object lookup. main round-trips a string via stringify(parse(input)).

Parsing covers objects, arrays, literals, integer-only numbers (rejects . / e), escapes including \u and surrogate pairs (UTF-8), whitespace rules, and raise on malformed input. Tests use a json() helper (single quotes → double quotes) because Rue literals lack escapes.

Also adds the usual examples/json.yaml compile/test snapshot and links the example in the README.

Reviewed by Cursor Bugbot for commit c26de19. Bugbot is set up for automated code reviews on this repo. Configure here.

@Rigidity
Rigidity merged commit 74471af into main Oct 24, 2026
3 checks passed
@Rigidity
Rigidity deleted the t3/json-example branch October 24, 2026 01:36
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.

1 participant