jmespath

    A standards-oriented JMESPath parser and JSON query engine in MoonBit.

    jmespath
    json
    query
    parser
    Download zip
    Version
    0.1.36
    License
    Apache-2.0
    Last updated
    20 minutes ago
    Downloads
    289

    No dependencies

    #MoonJMES

    MoonJMES is a MoonBit library and command-line tool for querying JSON with JMESPath. Use it to filter records, extract fields, project nested data, and sort reports. It supports the JS backend, with Node.js as the CLI host.

    Version 0.1.36 extends independent join work-budget verification and public size-boundary regressions. See the release verification record. Mooncakes package · Changelog

    #Install the library

    From an existing MoonBit module, install the exact release.

    moon add JingLan0v0/jmespath@0.1.36

    Use this moon.pkg for the minimal executable.

    import {
    "JingLan0v0/jmespath" @jmespath,
    }

    pkgtype(kind: "executable")

    In the same package, create main.mbt.

    fn main raise {
    let input = @jmespath.parse_json_bounded("{\"items\":[{\"name\":\"Ada\"}]}")
    let query = @jmespath.compile("items[*].name")
    println(@jmespath.stringify_bounded(query.search(input)))
    }

    Run moon run . --target js from that package. It prints ["Ada"]. The repository also includes a complete example with custom limits, query reuse, and error handling. Library example · API guide

    #Run the CLI from source

    Use MoonBit 0.10.20+65efd5b93 and Node.js 24.14.0 for the pinned build. Older MoonBit versions such as 0.10.14 cannot compile the current source. Toolchain configuration · Official installation instructions

    git clone https://github.com/JingLan0v0/moonbit-jmespath.git cd moonbit-jmespath moon run cmd/main --target js -- --compact "instances[?state == 'running'].id" examples/cloud-inventory.json

    Expected output is ["i-101","i-102","i-104"]. Pass - as the input path to read JSON from stdin. On Windows, scripts/moon.ps1 can select the pinned local toolchain. PowerShell commands · CLI usage

    #Try the checked examples

    node examples/demo.mjs

    ScenarioResult
    Cloud inventoryIDs and zones for running production instances
    Deployment policyBlocked services and their nested reason codes
    Cost reportServices sorted by monthly cost

    The demo asserts all three results against committed JSON. It also checks the quick start query and a batch that returns before, limit_exceeded, then after. Add --release to run the release build. Inputs, queries, and expected results

    Batch input is a JSON array of {"expression":"…","data":…} requests. When the batch is accepted, the CLI exits 0 and each response has its own ok flag and result or error. An invalid outer JSON document fails the whole invocation with exit 2 and empty stdout. Batch API and error contract

    #Limits and compatibility

    Default query limits include 16,384 Unicode scalars for the expression, AST depth 256, one million work steps, and 100,000 materialized result elements. The evaluator also caps active call depth at 128. The CLI reads at most 16 MiB of input, and a batch accepts at most 10,000 requests. Input and output shape checks bound JSON expansion. Non-string to_string conversions charge their conservative JSON size estimate before allocation. Resource limits

    Function error positions count Unicode scalars from zero. Results can share collections with caller input, and reused compiled queries keep independent evaluation state. Diagnostics and ownership

    #Verify a checkout

    node scripts/verify.mjs

    Windows and Ubuntu CI use this command. Debug and release each run unit tests, 892 pinned official JMESPath cases, the demos and resource-limit regressions. An independent model checks 34,350 work-budget boundaries and 518 batch neighbors per mode, including ordinary function arguments, runtime arity, Unicode scalar lengths, short-circuit logic and pipe contexts. Budget checks and replay. A separate numeric suite checks 640 string/raw-input cases per mode against independent binary64 expectations. Numeric verification. Verification also requires Python 3.10+ (CI: 3.13.17). Offline release-tool regressions and the version-independent public-API consumer fixture are included. Windows also checks PowerShell. The command writes _build/verification-summary.json. Verification setup · GitHub Actions

    The acceptance log records test results by commit, historical fixes, archive checks and fresh installation evidence. Acceptance evidence · Performance benchmarks

    #License and references

    MoonJMES is an independent implementation of the public JMESPath specification. Pinned upstream vectors are downloaded for verification. The project is licensed under Apache-2.0. License · Third-party notices

    JmesPathError

    pub(all) suberror JmesPathError {
    JmesPathError(Diagnostic)
    }

    CompareOp

    type CompareOp derive(Eq,
    Debug
    )

    CompareOp::equal

    fn CompareOp::equal(CompareOp, CompareOp) -> Bool
    automatically derived

    CompareOp::not_equal

    fn CompareOp::not_equal(x : CompareOp, y : CompareOp) -> Bool
    automatically derived

    CompareOp::to_repr

    automatically derived

    Compiled

    pub struct Compiled {
    source : String
    expr : Expr
    limits : Limits
    }

    Compiled::source

    fn Compiled::source(self : Compiled) -> String

    Diagnostic

    pub(all) struct Diagnostic {
    code : String
    offset : Int
    message : String
    } derive(Eq,
    Debug
    )

    Diagnostic::equal

    fn Diagnostic::equal(Diagnostic, Diagnostic) -> Bool
    automatically derived

    Diagnostic::not_equal

    fn Diagnostic::not_equal(x : Diagnostic, y : Diagnostic) -> Bool
    automatically derived

    Diagnostic::to_repr

    automatically derived

    Expr

    Expr::equal

    fn Expr::equal(Expr, Expr) -> Bool
    automatically derived

    Expr::not_equal

    fn Expr::not_equal(x : Expr, y : Expr) -> Bool
    automatically derived

    Expr::to_repr

    automatically derived

    Limits

    pub(all) struct Limits {
    max_expression_chars : Int
    max_ast_depth : Int
    max_steps : Int
    max_results : Int
    } derive(Eq,
    Debug
    )

    Limits::equal

    fn Limits::equal(Limits, Limits) -> Bool
    automatically derived

    Limits::not_equal

    fn Limits::not_equal(x : Limits, y : Limits) -> Bool
    automatically derived

    Limits::to_repr

    automatically derived

    Token

    Token::equal

    fn Token::equal(Token, Token) -> Bool
    automatically derived

    Token::not_equal

    fn Token::not_equal(x : Token, y : Token) -> Bool
    automatically derived

    Token::to_repr

    automatically derived

    TokenKind

    type TokenKind derive(Eq,
    Debug
    )

    TokenKind::equal

    fn TokenKind::equal(TokenKind, TokenKind) -> Bool
    automatically derived

    TokenKind::not_equal

    fn TokenKind::not_equal(x : TokenKind, y : TokenKind) -> Bool
    automatically derived

    TokenKind::to_repr

    automatically derived

    compile

    fn compile(source : String, limits? : Limits) -> Compiled raise JmesPathError

    default_limits

    fn default_limits() -> Limits

    parse_json_bounded

    fn parse_json_bounded(text : String) ->
    Json
    raise JmesPathError

    Preflight text allocation budgets, then parse JSON. This does not impose per-query JSON shape limits; batch callers retain independent item checks.
    fn search(expression : String, data :
    Json
    , limits? : Limits) ->
    Json
    raise JmesPathError

    search_batch

    Runs independent queries from a JSON array of {expression, data} objects. Errors are returned per item, so one invalid query or malformed request does not abort the batch. The top-level input must still be an array.

    search_json

    fn search_json(expression : String, json_text : String, limits? : Limits) ->
    Json
    raise JmesPathError

    stringify_bounded

    fn stringify_bounded(value :
    Json
    , pretty? : Bool) -> String raise JmesPathError

    Serialize after checking nesting, expanded node count, and a conservative output-size estimate. Pretty output uses two spaces and is also bounded.

    version

    fn version() -> String