#Nanaloveyuki/parsec/json

    json is a strict RFC 8259 parser. It rejects duplicate object keys, preserves number source text, accepts only JSON whitespace, and exposes configurable resource limits. It does not depend on JSON5, JSON-RPC, JSONPath, or JSONL.

    ///|
    test "parse strict JSON" {
    match @json.parse("{\"enabled\":true,\"retries\":3}") {
    Ok(Object(members~)) => inspect(members.length(), content="2")
    Err(_) => fail("expected JSON object")
    _ => fail("expected JSON object")
    }
    }

    Use JsonError::position with @lexer.Source to map an error offset to a one-based line and column. Conversion to another JSON representation, JSONL framing, JSONPath queries, JSON-RPC, and JSON5 remain separate packages.

    Json

    pub(all) enum Json {
    Null
    Bool(value~ : Bool)
    Number(raw~ : String)
    Text(value~ : String)
    Array(items~ : Array[Json])
    Object(members~ : Array[(String, Json)])
    }

    JsonError

    pub(all) enum JsonError {
    Syntax(error~ :
    ParseError
    )
    DuplicateKey(key~ : String, first_offset~ : Int, duplicate_offset~ : Int)
    Limit(kind~ : JsonLimitKind, offset~ : Int, limit~ : Int)
    }

    JsonError::offset

    fn JsonError::offset(self : JsonError) -> Int

    JsonLimitKind

    pub(all) enum JsonLimitKind {
    InputChars
    NestingDepth
    StringChars
    ArrayItems
    ObjectMembers
    }

    JsonLimits

    pub struct JsonLimits {
    // private fields
    }

    JsonLimits::new

    fn JsonLimits::new(max_input_chars~ : Int, max_depth~ : Int, max_string_chars~ : Int, max_array_items~ : Int, max_object_members~ : Int) -> JsonLimits

    JsonLimits::standard

    fn JsonLimits::standard() -> JsonLimits

    parse

    fn parse(input : String) -> Result[Json, JsonError]

    parse_with_limits

    fn parse_with_limits(input : String, limits : JsonLimits) -> Result[Json, JsonError]

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io