{
  "slug": "bson-extended-json-converter",
  "name": "gizza-ai/bson-extended-json-converter",
  "version": "0.1.0",
  "title": "MongoDB Extended JSON Converter — gizza.ai",
  "description": "Convert MongoDB Extended JSON ($oid, $date, $numberLong) to and from plain JSON, with canonical or relaxed output, in your browser.",
  "tags": [
    "mongodb",
    "bson",
    "extended-json",
    "ejson",
    "json",
    "oid",
    "objectid",
    "converter",
    "developer"
  ],
  "category": "data",
  "urls": {
    "page": "https://gizza.ai/tools/bson-extended-json-converter/",
    "markdown": "https://gizza.ai/tools/bson-extended-json-converter/index.md",
    "descriptor": "https://gizza.ai/tools/bson-extended-json-converter/tool.json",
    "deep_link_example": "https://gizza.ai/tools/bson-extended-json-converter/?input=%7B%22_id%22%3A%7B%22%24oid%22%3A%22507f1f77bcf86cd799439011%22%7D%2C%22created%22%3A%7B%22%24date%22%3A%222024-07-20T14%3A30%3A00Z%22%7D%7D&direction=auto&mode=relaxed&date_format=iso&detect_types=true&big_numbers_as_strings=true&pretty=true"
  },
  "cli": "gizza tool bson-extended-json-converter '{\"_id\":{\"$oid\":\"507f1f77bcf86cd799439011\"},\"created\":{\"$date\":\"2024-07-20T14:30:00Z\"}}'",
  "tool": {
    "description": "Convert MongoDB Extended JSON (the BSON wrapper dialect with $oid, $date, $numberLong, $numberDecimal, $binary, $regularExpression, $timestamp, $minKey, $maxKey, $undefined, $symbol, $code/$scope and $dbPointer) to and from plain JSON. direction=auto detects which way to convert; to-plain unwraps every typed value into ordinary JSON; to-extended wraps plain JSON and also re-normalises Extended JSON between the relaxed and canonical dialects (mode). Canonical v2, relaxed v2 and the legacy v1 spellings ({\"$date\": 1721485800000}, {\"$binary\": \"...\", \"$type\": \"00\"}, {\"$regex\": \"...\", \"$options\": \"i\"}) are all accepted on input. date_format picks ISO-8601 or epoch millis for unwrapped dates; big_numbers_as_strings keeps 64-bit and Decimal128 values exact; detect_types optionally promotes 24-hex and ISO-8601 strings to $oid and $date when wrapping; pretty toggles indented vs compact output. Document key order is preserved, and DBRef ($ref/$id/$db) round-trips as the ordinary subdocument it is. Errors name the offending field path. Runs locally; no MongoDB driver or network.",
    "parameters": {
      "additionalProperties": false,
      "properties": {
        "big_numbers_as_strings": {
          "default": false,
          "description": "When converting to plain JSON, emit 64-bit integers ($numberLong) and Decimal128 values ($numberDecimal) as JSON strings instead of numbers, so values beyond JavaScript's safe-integer range keep full precision. Infinity and NaN are always strings because JSON has no literal for them.",
          "type": "boolean"
        },
        "date_format": {
          "default": "iso",
          "description": "How a BSON date renders when converting to plain JSON: iso gives an ISO-8601 UTC string like \"2024-07-20T14:30:00Z\"; epoch-millis gives the raw millisecond count like 1721485800000. Ignored when converting to Extended JSON.",
          "enum": [
            "iso",
            "epoch-millis"
          ],
          "type": "string"
        },
        "detect_types": {
          "default": false,
          "description": "When converting plain JSON to Extended JSON, promote strings that look like values: a 24-character hex string becomes {\"$oid\": ...} and a full ISO-8601 date-time becomes {\"$date\": ...}. Off by default because the guess can be wrong for ordinary hex or date-like strings.",
          "type": "boolean"
        },
        "direction": {
          "default": "auto",
          "description": "auto picks the direction from the input shape (any recognised $-wrapper means unwrap, otherwise wrap); to-plain strips the typed wrappers down to plain JSON; to-extended wraps values in Extended JSON, which also re-normalises Extended JSON input into the chosen mode.",
          "enum": [
            "auto",
            "to-plain",
            "to-extended"
          ],
          "type": "string"
        },
        "input": {
          "description": "The JSON to convert. Either MongoDB Extended JSON (e.g. {\"_id\":{\"$oid\":\"507f1f77bcf86cd799439011\"}}) or plain JSON (e.g. {\"_id\":\"507f1f77bcf86cd799439011\"}). Objects, arrays and scalars are all accepted.",
          "type": "string"
        },
        "mode": {
          "default": "relaxed",
          "description": "Which Extended JSON dialect to emit when converting to Extended JSON. relaxed keeps plain numbers and ISO-8601 dates for readability; canonical wraps every number and date ($numberInt, $numberLong, $numberDouble, $date/$numberLong) so the exact BSON type survives. Ignored when converting to plain JSON.",
          "enum": [
            "relaxed",
            "canonical"
          ],
          "type": "string"
        },
        "pretty": {
          "default": true,
          "description": "Pretty-print (indent) the JSON output. Set false for compact single-line output.",
          "type": "boolean"
        }
      },
      "required": [
        "input"
      ],
      "type": "object"
    }
  }
}