MoonJSONPath 面向 MoonBit 工具链、配置处理、API 客户端、测试 fixture、LLM tool-call 数据处理等场景,提供对 JSON 文档的标准化定位、查询和轻量修改能力。开发者可以使用 JSON Pointer 精确访问或更新一个节点,也可以使用 JSONPath 从复杂 JSON 中批量查询匹配值,并获得每个匹配值对应的 JSON Pointer 路径
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
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.