目录

MoonBit JSONPath

MoonBit License

MoonBit JSONPath is a small JSONPath parser and evaluator written in MoonBit. It targets the core query patterns described by RFC 9535 and integrates directly with moonbitlang/core/json.

The project is maintained for the MoonBit Open Source Ecosystem Competition 2026. The public repositories are:

Features

  • Parses JSONPath strings into a compact MoonBit AST.
  • Evaluates queries against Json values from moonbitlang/core/json.
  • Supports root, child, bracket child, recursive descendant, wildcard, and array index selectors.
  • Ships focused unit tests and a runnable CLI example.
  • Uses the Apache-2.0 license.

Installation

The module name is:

ppyj663/moon-jsonpath

Install the published Mooncakes package from your project root:

moon add ppyj663/moon-jsonpath

Then import it from a package:

import {
  "ppyj663/moon-jsonpath" @jsonpath,
}

Quick Start

let json = @json.parse(
  #|{
  #|  "store": {
  #|    "book": [
  #|      { "title": "Sayings of the Century", "price": 8.95 },
  #|      { "title": "Sword of Honour", "price": 12.99 }
  #|    ]
  #|  }
  #|}
)

match @jsonpath.query(json, "$.store.book[0].title") {
  Ok(values) => println(values[0].stringify())
  Err(message) => println("query failed: \{message}")
}

Run the included example:

moon run cmd/main

Expected output:

query: $.store.book[0].title
matches: 1
"Sayings of the Century"

Supported Syntax

Syntax Meaning Example
$ Root node $
.<name> Object child selector $.store.bicycle
['<name>'] or ["<name>"] Bracket child selector $['store']['book']
.. <name> without the space Recursive descendant selector $..price
.* / [*] Object or array wildcard $.store.book[*]
[<number>] Zero-based array index $.store.book[0]

Not yet supported: filters such as [?(@.price < 10)], slices, unions, negative indices, and function extensions.

API

pub fn parse(input : String) -> Result[JSONPath, String]
pub fn evaluate(json : Json, path : JSONPath) -> Array[Json]
pub fn query(json : Json, path_str : String) -> Result[Array[Json], String]

query is the usual entry point. It returns Err(message) for unsupported or malformed JSONPath syntax and returns an empty array when a valid query simply finds no matching node.

Development

moon update
moon fmt --check
moon check --warn-list +73
moon test
moon run cmd/main

The repository also contains a GitHub Actions workflow that runs the same verification path on every push and pull request.

Mooncakes package ppyj663/moon-jsonpath version 0.1.0 is published. The release was validated with moon package, moon publish --dry-run, and moon publish.

Competition Closeout

Closeout evidence is tracked in docs/competition/acceptance.md. The one-page project report is report.pdf.

License

This project is released under the Apache License 2.0.

关于

JSONPath(RFC 9535 标准)是一种类似于 XPath 的查询语言,主要用于从复杂的 JSON 数据结构中精确地查询、过滤和提取节点数据。由于 JSON 是各种 API 和配置文件的核心,为强类型的 MoonBit 提供一个标准的 JSONPath 查询库,对于其后端生态(Web框架、配置管理等)具有极大的帮助。

840.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802047560号