{
  "id": "json-batch-encode",
  "name": "Exact UTF-8 JSON batch encoder",
  "description": "WHEN TO USE: Produce contiguous, greedy, byte-bounded JSON-array or LF-terminated NDJSON wire bodies from supplied JSON values. Counts actual UTF-8 bodies including framing and escaping; optional SHA-256 hashes those unchanged bytes. Uses recursive key sorting plus JSON.stringify, not RFC 8785; rejects malformed Unicode and oversized records without partial batches. No transmission, endpoint-limit verification, compression or token accounting.",
  "category": "structured",
  "priceUsd": "0.003",
  "pricingStatus": "proposed-unverified",
  "pricing": {
    "unit": "one successful operation call",
    "proposedNominalUsd": "0.003",
    "sixDecimalTokenBaseUnits": "3000",
    "subscription": false,
    "includesPayerWalletOrNetworkFees": false,
    "liveQuoteVerified": false,
    "condition": "Actual SDK challenge is authoritative only within the caller's explicit authorization; configured six-decimal token peg is an operator assertion, not a conversion guarantee."
  },
  "intents": [
    "Encode exact byte-limited JSON array or NDJSON request payload batches",
    "Pack JSON records into contiguous UTF-8-sized bodies without splitting records",
    "Measure escaped JSON framing and hash unchanged batch wire bytes"
  ],
  "whenToUse": [
    "Encode exact byte-limited JSON array or NDJSON request payload batches",
    "Pack JSON records into contiguous UTF-8-sized bodies without splitting records",
    "Measure escaped JSON framing and hash unchanged batch wire bytes"
  ],
  "whenNotToUse": [
    "Sending requests, validating target endpoint schemas or actual server limits, sizing headers, HTTP framing, compression or tokenization",
    "Arbitrary-precision JSON numbers or RFC 8785 cryptographic canonicalization",
    "Fetching data, executing caller code, contacting agents, transmitting a payload, or changing remote state",
    "Verifying semantic truth, source authenticity, identity, permissions, or business relationships"
  ],
  "capabilities": [
    "Actual body UTF-8 byte counts, not the result wrapper representation",
    "Greedy contiguous record-preserving batches with hard item and byte caps",
    "Recursive sorted-key JSON.stringify profile; array order retained and final LF required for NDJSON",
    "Single oversized record rejects all output; optional SHA-256 hashes exact body bytes",
    "Networkless deterministic transforms; externalRequests=0; semanticValidityVerified=false"
  ],
  "limits": {
    "inputBytes": 100000,
    "outputBytes": 400000,
    "jsonNodes": 12000,
    "depth": 20,
    "maxRecords": 500,
    "maxUtf8Bytes": 100000,
    "maxItemsPerBatch": 500,
    "maxBatches": 500,
    "serialization": "recursive sorted-key JSON.stringify; integer-index keys first numerically",
    "ndjsonFinalLf": "always on nonempty batches"
  },
  "related": [
    "json-canonicalize",
    "ndjson-inspect",
    "message-batch-plan"
  ],
  "errorCodes": [
    "INPUT_LIMIT",
    "OUTPUT_LIMIT",
    "COMPLEXITY_LIMIT",
    "INVALID_JSON",
    "INVALID_NUMBER",
    "INVALID_UNICODE",
    "UNSAFE_KEY",
    "RECORD_TOO_LARGE"
  ],
  "requirementsProfile": {
    "format": "declared-requirements-v1",
    "facts": {
      "execution.suppliedCode": false,
      "execution.remoteMutation": false,
      "execution.llmInference": false,
      "execution.paidMcp": false,
      "verification.semanticTruth": false,
      "verification.sourceAuthenticity": false,
      "verification.liveVulnerabilities": false,
      "numbers.arbitraryPrecisionJson": false,
      "numbers.model": "ieee754-binary64",
      "privacy.requestBodyPersisted": false,
      "execution.deterministic": true,
      "execution.networkAccess": false,
      "privacy.resultBodyPersisted": false,
      "payment.x402": true,
      "payment.mpp": true,
      "operation.id": "json-batch-encode",
      "operation.category": "structured",
      "limit.httpRequestBytes": 131072,
      "limit.requestBytes": 100000,
      "limit.responseBytes": 524288,
      "limit.resultBytes": 400000,
      "limit.jsonDepth": 20,
      "limit.jsonNodes": 12000,
      "jsonBatch.profile": "sorted-json-utf8-batches-v1",
      "jsonBatch.maxRecords": 500,
      "jsonBatch.maxItemsPerBatch": 500,
      "jsonBatch.maxUtf8BytesPerBatch": 100000,
      "jsonBatch.maxBatches": 500,
      "jsonBatch.byteMeasure": "returned-body-utf8",
      "jsonBatch.recordSplitting": false,
      "jsonBatch.transmitsBodies": false,
      "jsonBatch.httpHeadersIncluded": false,
      "jsonBatch.endpointLimitVerified": false,
      "jsonBatch.rfc8785Canonicalization": false,
      "input.records.maxItems": 500,
      "input.maxUtf8Bytes.maximum": 100000,
      "input.maxUtf8Bytes.minimum": 1,
      "input.maxItemsPerBatch.maximum": 500,
      "input.maxItemsPerBatch.minimum": 1
    },
    "unknownPolicy": "Undeclared requirements are unknown, never compatible. Matching declared facts does not establish semantic fit or input validity.",
    "preflight": "/preflight"
  },
  "documentation": "/reference/tools/json-batch-encode.md",
  "serviceContract": "/reference/services/json-batch-encode.json",
  "errors": [
    {
      "status": 400,
      "meaning": "Malformed JSON, missing/invalid idempotency key, or payment identifier mismatch",
      "retry": "Correct the request before payment"
    },
    {
      "status": 402,
      "meaning": "Payment challenge or rejected payment",
      "retry": "Use official protocol SDK; inspect payment outcome before another payment"
    },
    {
      "status": 409,
      "meaning": "Idempotency conflict, duplicate proof, or PAYMENT_UNCERTAIN",
      "retry": "Keep original key, body, and proof; reconcile uncertainty with operator; never blindly repay"
    },
    {
      "status": 413,
      "meaning": "Input or generated output too large",
      "retry": "Reduce input; no payment attempted for validation failure"
    },
    {
      "status": 415,
      "meaning": "Unsupported media type or compression",
      "retry": "Send uncompressed application/json"
    },
    {
      "status": 422,
      "meaning": "Schema or service-specific semantic validation failure",
      "retry": "Correct input using returned error code; no payment attempted"
    },
    {
      "status": 429,
      "meaning": "Request/payment-attempt rate exceeded",
      "retry": "Wait for rate limit window; preserve existing payment identity"
    },
    {
      "status": 503,
      "meaning": "Payment configuration/provider/state unavailable, or live DNS preparation failed before settlement",
      "retry": "Check readiness; DNS preparation failures may retry the identical key/body/credential only; uncertainty requires reconciliation"
    }
  ],
  "numericPrecision": "JavaScript IEEE-754 numbers; use strings for large integer IDs/exact decimals where the schema accepts strings. No lossless numeric parsing.",
  "paymentWorkflow": {
    "discoveryOnly": false,
    "supportedProtocols": [
      "x402",
      "mpp"
    ],
    "x402": {
      "credentialHeader": "PAYMENT-SIGNATURE",
      "challengeHeader": "PAYMENT-REQUIRED",
      "receiptHeader": "PAYMENT-RESPONSE",
      "version": 2,
      "scheme": "exact",
      "paymentIdentifier": "payment-identifier extension MUST equal the HTTP Idempotency-Key",
      "sdk": "@x402/core with @x402/evm"
    },
    "mpp": {
      "supported": true,
      "credentialHeader": "Authorization",
      "challengeHeader": "WWW-Authenticate",
      "receiptHeader": "Payment-Receipt",
      "method": "tempo",
      "intent": "charge",
      "sdk": "mppx",
      "tokenDecimals": 6
    },
    "steps": [
      "Check configured readiness and the exact service schema",
      "Generate a fresh random Idempotency-Key for this operation; never use a discovery probe fixture for purchases",
      "Send valid input without a credential to obtain the official protocol challenge",
      "Use the official SDK and authorized wallet to fulfill the challenge",
      "Retry only with identical key, body, protocol and credential",
      "On PAYMENT_UNCERTAIN stop and request operator reconciliation; never blindly pay again"
    ],
    "versionedRetries": "Request fingerprint includes service release version. Retries across a version upgrade can conflict; coordinate upgrades outside the 24-hour replay window and reconcile pending attempts.",
    "docs": "/llms.txt"
  },
  "method": "POST",
  "paths": {
    "x402": "/v1/x402/json-batch-encode",
    "mpp": "/v1/mpp/json-batch-encode"
  },
  "inputSchema": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "records": {
        "maxItems": 500,
        "type": "array",
        "items": {
          "$ref": "#/$defs/__schema0"
        }
      },
      "framing": {
        "type": "string",
        "enum": [
          "json-array",
          "ndjson-lf"
        ]
      },
      "maxUtf8Bytes": {
        "type": "integer",
        "minimum": 1,
        "maximum": 100000
      },
      "maxItemsPerBatch": {
        "type": "integer",
        "minimum": 1,
        "maximum": 500
      },
      "includeSha256": {
        "default": false,
        "type": "boolean"
      }
    },
    "required": [
      "records",
      "framing",
      "maxUtf8Bytes",
      "maxItemsPerBatch"
    ],
    "additionalProperties": false,
    "$defs": {
      "__schema0": {
        "anyOf": [
          {
            "type": "string"
          },
          {
            "type": "number"
          },
          {
            "type": "boolean"
          },
          {
            "type": "null"
          },
          {
            "type": "array",
            "items": {
              "$ref": "#/$defs/__schema0"
            }
          },
          {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "$ref": "#/$defs/__schema0"
            }
          }
        ]
      }
    }
  },
  "outputSchema": {
    "type": "object",
    "required": [
      "operation",
      "version",
      "result",
      "provenance"
    ],
    "properties": {
      "operation": {
        "const": "json-batch-encode",
        "type": "string"
      },
      "version": {
        "const": "0.29.0",
        "type": "string"
      },
      "result": {
        "$schema": "https://json-schema.org/draft/2020-12/schema",
        "type": "object",
        "properties": {
          "profile": {
            "type": "string",
            "const": "sorted-json-utf8-batches-v1"
          },
          "framing": {
            "type": "string",
            "enum": [
              "json-array",
              "ndjson-lf"
            ]
          },
          "batches": {
            "maxItems": 500,
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "itemIndexes": {
                  "minItems": 1,
                  "maxItems": 500,
                  "type": "array",
                  "items": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 499
                  }
                },
                "bodyText": {
                  "type": "string",
                  "maxLength": 100000
                },
                "utf8Bytes": {
                  "type": "integer",
                  "minimum": 1,
                  "maximum": 100000
                },
                "sha256": {
                  "type": "string",
                  "pattern": "^[0-9a-f]{64}$"
                }
              },
              "required": [
                "itemIndexes",
                "bodyText",
                "utf8Bytes"
              ],
              "additionalProperties": false
            }
          },
          "itemCount": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "batchCount": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "totalUtf8Bytes": {
            "type": "integer",
            "minimum": 0,
            "maximum": 9007199254740991
          },
          "externalRequests": {
            "type": "number",
            "const": 0
          },
          "semanticValidityVerified": {
            "type": "boolean",
            "const": false
          }
        },
        "required": [
          "profile",
          "framing",
          "batches",
          "itemCount",
          "batchCount",
          "totalUtf8Bytes",
          "externalRequests",
          "semanticValidityVerified"
        ],
        "additionalProperties": false
      },
      "provenance": {
        "type": "object",
        "required": [
          "inputSha256",
          "outputSha256",
          "deterministic",
          "externalRequests"
        ],
        "properties": {
          "inputSha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "outputSha256": {
            "type": "string",
            "pattern": "^[a-f0-9]{64}$"
          },
          "deterministic": {
            "const": true
          },
          "externalRequests": {
            "const": 0
          }
        }
      }
    },
    "additionalProperties": false
  },
  "exampleInput": {
    "records": [
      {
        "x": "é"
      },
      {
        "x": "a"
      },
      {
        "x": "😀"
      }
    ],
    "framing": "json-array",
    "maxUtf8Bytes": 23,
    "maxItemsPerBatch": 100,
    "includeSha256": true
  },
  "exampleResponse": {
    "operation": "json-batch-encode",
    "version": "0.29.0",
    "result": {
      "profile": "sorted-json-utf8-batches-v1",
      "framing": "json-array",
      "batches": [
        {
          "itemIndexes": [
            0,
            1
          ],
          "bodyText": "[{\"x\":\"é\"},{\"x\":\"a\"}]",
          "utf8Bytes": 22,
          "sha256": "2806c29934df94f04cf761490e60e34550c4b905e5bce434c874377c74d5bd1f"
        },
        {
          "itemIndexes": [
            2
          ],
          "bodyText": "[{\"x\":\"😀\"}]",
          "utf8Bytes": 14,
          "sha256": "62ec360b21da91f071c8ce7a2866d45c424c8f162eecb1dc504d8b32de7a0cc7"
        }
      ],
      "itemCount": 3,
      "batchCount": 2,
      "totalUtf8Bytes": 36,
      "externalRequests": 0,
      "semanticValidityVerified": false
    },
    "provenance": {
      "inputSha256": "d9cc3efaf7a499898a72fd490b169cb52507707b5cd1a1651b4dd9d21a06139d",
      "outputSha256": "aef8b58f28ceab34c9424ba2b58eeecb3b82d2d92d1319868c84336f3aceaedd",
      "deterministic": true,
      "externalRequests": 0
    }
  },
  "requiredHeaders": {
    "Content-Type": "application/json",
    "Idempotency-Key": "random 16–128 character operation identifier"
  },
  "fixedExample": "/reference/examples/json-batch-encode.json",
  "execution": {
    "deterministic": true,
    "externalRequests": 0,
    "maxExternalRequests": 0,
    "resultSnapshotPersisted": false,
    "fixedExampleIsIllustrativeSnapshot": false,
    "requiresPayment": true,
    "supportsMcpExecution": false
  },
  "releaseSnapshot": {
    "format": "static-release-reference-v1",
    "sourceVersion": "0.29.0",
    "sourceRegistrySha256": "a2b5ec09bf6c38b9d2879d746a4fded374f5928b445377b0270ef6aa8e6cac65",
    "generatedAt": "2026-10-06T15:38:00Z",
    "releaseAcceptance": "not-verified-by-generator",
    "runtimeReadiness": "not-evaluated",
    "livePaymentsVerified": false,
    "indexingVerified": false,
    "apiOrigin": null,
    "notice": "Build-time release reference. Runtime readiness, deployment, payment settlement and external indexing are not evaluated here. Prices are proposed; this file cannot authorize execution or payment."
  }
}
