Corvus.Text.Json

repository·main·Indexed 41 days ago

https://github.com/corvus-dotnet/corvus.jsonschema

A high-performance C# library for working with JSON Schema. It provides source-generated, strongly-typed models, efficient pooled-memory parsing, and query and transformation capabilities including JSONata and JMESPath. The ecosystem includes the Corvus.Text.Json.SourceGenerator for compilation-time type production and the Corvus.Json.CodeGenerator CLI tool for ahead-of-time (AOT) code generation.

Tokens
344.9K
Snippets
954
Records
1.4K
Agent score
52%

What's inside Corvus.Text.Json

  1. Overview of Corvus.Text.Json.OpenApi.CodeGeneration

    main

    Corvus.Text.Json.OpenApi.CodeGeneration is a tool for generating strongly-typed .NET API clients and servers from OpenAPI and AsyncAPI specifications.

    Unlike traditional generators that create intermediate object models requiring deserialization, this tool produces C# code that parses API responses directly into document-backed value types using the Corvus.Text.Json zero-allocation engine. This approach eliminates intermediate object models and avoids allocations on the 'happy path' of API execution.

  2. Overview of Corvus.Json V4 capabilities

    main

    The Corvus.Json V4 engine provides a high-performance, System.Text.Json-based approach to working with JSON schemas in C#. Key capabilities include:

    • Code Generation: Generating full-fidelity .NET type models from JSON schemas using the corvusjson tool (or the legacy Corvus.Json.CodeGenerator).
    • Serialization & Deserialization: Using generated code to convert between JSON documents and .NET types.
    • Validation: Performing optimized schema validation during processing.
    • Navigation & Exploration: Navigating JSON documents and exploring unknown or undocumented JSON structures using Corvus.Json.ExtendedTypes.
    • Composition: Creating, transforming, and composing JSON documents from various sources with minimal allocations and copying.
  3. Overview of Corvus.Text.Json.JsonPath

    main

    JSONPath Query Language

    Corvus.Text.Json.JsonPath implements the RFC 9535 standard for querying JSON documents. It is a high-performance implementation designed for the Corvus.Text.Json document model, featuring a plan-based interpreter, fused execution steps, and zero-allocation result buffers.

    Key Features:

    • Full Conformance: Passes all 723 test cases in the official JSONPath Compliance Test Suite.
    • Selector Support: Property access, wildcards, array index/slice selectors, recursive descent ($..), and filter expressions.
    • Function Extensions: Supports length, count, value, match, and search, as well as custom extensions.
    • Performance: Highly optimized with minimal allocations (fixed 152 bytes per evaluation for the ParsedJsonDocument).

    Choosing between JSONPath and JMESPath

    • Use JSONPath if you need the IETF standard (RFC 9535) or node selection (returning the actual matched nodes). It is ideal for recursive descent ($..).
    • Use JMESPath if you need data extraction and reshaping (projections, multiselect, and pipe expressions).
  4. Overview of Corvus.Text.Json.OpenApi20

    main
    Corvus.Text.Json.OpenApi20 provides strongly-typed V5 model types for OpenAPI 2.0 (Swagger) specifications. These models are generated from the official Swagger 2.0 JSON Schema metaschema (id: http://swagger.io/v2/schema.json#, JSON Schema draft-04). The generation is performed using the Corvus.Text.Json source generator, ensuring the models are committed verbatim from the OpenAPI-Specification repository's _archive_/schemas/v2.0/schema.json.
  5. Overview of Corvus.Text.Json.JsonLogic

    main

    Corvus.Text.Json.JsonLogic is a rule engine for JsonLogic designed for high performance. Key features include:

    • Zero-allocation bytecode VM evaluation: Minimizes memory pressure during rule execution.
    • Pluggable operators: Allows for extending the engine with custom logic.
    • Compile-time constant folding: Optimizes rules by evaluating constant expressions during compilation.
  6. Introduction to Corvus.Text.Json

    main

    Corvus.Text.Json is a high-performance JSON processing library designed for zero-allocation performance on the hot path. It allows developers to define a JSON Schema and then use a source generator to create strongly-typed C# structs. These generated types enable efficient parsing, querying, creation, mutation, serialization, and validation of JSON data.

    Key capabilities include:

    • Schema-driven development: Generate C# types directly from JSON Schemas.
    • High performance: Optimized for zero-allocation during critical operations.
    • Strong typing: Use C# structs for parsing and manipulating JSON, including support for complex types like nested objects, arrays, and oneOf composition.
    • Full lifecycle support: Handle everything from initial parsing and property access to mutation, serialization via pooled writers, and schema validation with detailed error reporting.
  7. Introduction to the V4 Engine (Corvus.Json)

    main

    The V4 engine is designed for JSON Schema-based code generation using Corvus.Json.ExtendedTypes and Corvus.Json.JsonSchema.TypeGeneratorTool. It leverages System.Text.Json to provide support for:

    • Rich serialization and deserialization.
    • Type composition and validation against JSON Schemas.
    • Navigation of JSON documents (including arrays, union types, and additional properties).
    • Creation of JSON documents via factory methods.
    • Pattern matching for oneOf and anyOf union types.

    Note: If you require source-generator integration, pooled-memory parsing, or mutable documents, use the V5 engine (Corvus.Text.Json) instead.

  8. Overview of the Corvus.Text.Json namespace

    main

    The Corvus.Text.Json namespace is the primary public API for Corvus.Text.Json. It provides high-performance, strongly-typed tools for working with JSON documents using pooled-memory models generated from JSON Schema.

    Key capabilities include:

    • Parsing and Reading: Use ParsedJsonDocument<T> for read-only, pooled-memory parsing of JSON documents into strongly-typed models.
    • Building and Mutation: Use JsonDocumentBuilder<T> for mutable document construction, or JsonElement.Mutable for working with mutable builder variants.
    • Value Representation: JsonElement serves as the immutable value type, while JsonElement.Source allows for implicit conversions from standard .NET primitives.
    • Memory Management: JsonWorkspace manages pooled memory to ensure high performance and low allocation.
    • Streaming I/O: High-performance streaming is provided via Utf8JsonReader and Utf8JsonWriter.
    • URI Handling: Specialized URI types like Utf8Uri and Utf8IriReference enable zero-allocation URI parsing and validation, specifically designed for JSON Schema format keywords.