MoonJSONPath is a MoonBit-native JSON Pointer, JSONPath, and lightweight JSON
patch toolkit. It helps MoonBit programs locate, inspect, and update structured
JSON data without hand-written recursive traversal code.
This project is designed for MoonBit tooling, configuration validation, API
clients, documentation processing, test fixtures, and LLM tool-calling
workflows.
Highlights
JSON Pointer parser and formatter compatible with RFC 6901 escaping.
JSON Pointer get, set, remove, and URI fragment helpers.
JSONPath query engine with members, quoted members, arrays, wildcards,
recursive descent, slices, unions, filters, and match locations.
moon run cmd/main -- query '$.users[*].name' users.json
# ["Ada","Grace"]
moon run cmd/main -- query --pointers '$.users[*].name' users.json
# ["/users/0/name","/users/1/name"]
moon run cmd/main -- get '/users/0/name' users.json
# "Ada"
moon run cmd/main -- set '/users/0/active' true users.json
# {"users":[{"name":"Ada","active":true},{"name":"Grace","active":true}]}
File input is supported through moonbitlang/x/fs. Direct stdin reading is not
claimed yet because the MoonBit standard/x packages used here do not currently
expose a stable stdin API.
JSON Pointer parsing, escaping, reading, setting, removing, and URI fragments
JSONPath parsing, selection, filters, formatting, diagnostics, and helpers
Pointer Patch operations and error reporting
CLI command parsing and text execution
RFC-style conformance catalog cases
Workflow, operator reference, readiness, and submission evidence catalogs
At the time this README was written, the project has 65 passing tests and just
over 7k MoonBit source lines.
Scope and Non-goals
MoonJSONPath is not a jq clone. jq is a full JSON programming language with
pipes, functions, object construction, reductions, arithmetic, and many
transformation operators. MoonJSONPath focuses on a compact, testable query and
location layer for MoonBit projects.
Current non-goals:
full jq compatibility
arbitrary script expressions inside filters
full RFC 9535 regular-expression predicates
streaming parser
direct stdin support before a stable MoonBit API is available
claiming full RFC 6902 compatibility for the patch layer
Contest Notes
MoonJSONPath is an original MoonBit implementation inspired by open standards:
JSON Pointer RFC 6901 and the JSONPath RFC 9535 query model. It is not a port
of one upstream repository.
The repository includes runnable examples, focused tests, conformance-style
catalogs, structured documentation generators, and a CLI suitable for local
demonstration during contest review.
License
This project is licensed under the Apache License 2.0. See LICENSE.
MoonJSONPath
MoonJSONPath is a MoonBit-native JSON Pointer, JSONPath, and lightweight JSON patch toolkit. It helps MoonBit programs locate, inspect, and update structured JSON data without hand-written recursive traversal code.
This project is designed for MoonBit tooling, configuration validation, API clients, documentation processing, test fixtures, and LLM tool-calling workflows.
Highlights
get,set,remove, and URI fragment helpers.&&,||,!, grouped expressions,contains,starts_with,ends_with, and.length.add,replace,remove,test,copy, andmove.query,get,set,remove, andpatch.{ path, value }match objects.Quick Start
Install MoonBit, then run the test suite from the project root:
Run the CLI:
Running without arguments prints help:
Library Example
JSON Pointer
JSON Pointer identifies one exact location inside a JSON document.
Supported Pointer features:
""/user/name/users/0/a~1bfora/b,/m~0nform~n#/users/0/namesetandremoveJSONPath
JSONPath queries can return multiple matches. Each match includes both the value and its JSON Pointer location.
Supported JSONPath selectors:
$$.users$['display name']$.users[0]$.users[-1]$.users[*],$.meta.*$..name$.items[1:4],$.items[::-1]$.items[0,2],$.meta['owner','count']$.users[?(@.active == true)]Filter examples:
Pointer Patch
MoonJSONPath includes a lightweight pointer-based transformation layer.
Patch operation constructors:
PatchOp::add(path, value)PatchOp::replace(path, value)PatchOp::remove(path)PatchOp::assert_value(path, value)PatchOp::copy(from, path)PatchOp::move_to(from, path)PatchOp::parse_many(json)The patch layer is intentionally documented as MoonJSONPath’s own lightweight transform API. It is not advertised as full RFC 6902 compatibility.
CLI Usage
Example input:
Examples:
File input is supported through
moonbitlang/x/fs. Direct stdin reading is not claimed yet because the MoonBit standard/x packages used here do not currently expose a stable stdin API.Public API Overview
Core query APIs:
Path::compile(input)Path::query(doc)Path::to_string()Path::first(doc)Path::exists(doc)Path::values(doc)Path::pointers(doc)Path::explain()query_json_text(path, json)query_json_file(path, file)Pointer APIs:
Pointer::parse(input)Pointer::parse_uri_fragment(input)Pointer::to_string()Pointer::to_uri_fragment()Pointer::tokens()Pointer::get(doc)Pointer::set(doc, value)Pointer::remove(doc)Text transform helpers:
pointer_get_json_text(pointer, json_text)pointer_set_json_text(pointer, value_text, json_text)pointer_remove_json_text(pointer, json_text)patch_json_text(patch_text, json_text)Documentation and demo data generators:
cookbook_markdown()scenario_catalog_markdown()operator_reference_markdown()readiness_matrix_markdown()submission_evidence_markdown()longform_handbook()Project Structure
Testing
Run:
The test suite covers:
At the time this README was written, the project has 65 passing tests and just over 7k MoonBit source lines.
Scope and Non-goals
MoonJSONPath is not a
jqclone.jqis a full JSON programming language with pipes, functions, object construction, reductions, arithmetic, and many transformation operators. MoonJSONPath focuses on a compact, testable query and location layer for MoonBit projects.Current non-goals:
jqcompatibilityContest Notes
MoonJSONPath is an original MoonBit implementation inspired by open standards: JSON Pointer RFC 6901 and the JSONPath RFC 9535 query model. It is not a port of one upstream repository.
The repository includes runnable examples, focused tests, conformance-style catalogs, structured documentation generators, and a CLI suitable for local demonstration during contest review.
License
This project is licensed under the Apache License 2.0. See LICENSE.