etoon 0.7.2

Fast TOON (Token-Oriented Object Notation) encoder tracking spec v4.1. Up to 7.6x faster than toons, 3.0-8.3x faster than the official TS SDK.
Documentation
{
  "version": "4.0",
  "category": "encode",
  "description": "Tabular array encoding – arrays of uniform objects with primitive values",
  "tests": [
    {
      "name": "encodes arrays of uniform objects in tabular form",
      "input": {
        "items": [
          { "sku": "A1", "qty": 2, "price": 9.99 },
          { "sku": "B2", "qty": 1, "price": 14.5 }
        ]
      },
      "expected": "items[2]{sku,qty,price}:\n  A1,2,9.99\n  B2,1,14.5",
      "specSection": "9.3"
    },
    {
      "name": "encodes null values in tabular form",
      "input": {
        "items": [
          { "id": 1, "value": null },
          { "id": 2, "value": "test" }
        ]
      },
      "expected": "items[2]{id,value}:\n  1,null\n  2,test",
      "specSection": "9.3"
    },
    {
      "name": "quotes strings containing delimiters in tabular rows",
      "input": {
        "items": [
          { "sku": "A,1", "desc": "cool", "qty": 2 },
          { "sku": "B2", "desc": "wip: test", "qty": 1 }
        ]
      },
      "expected": "items[2]{sku,desc,qty}:\n  \"A,1\",cool,2\n  B2,\"wip: test\",1",
      "specSection": "9.3"
    },
    {
      "name": "quotes ambiguous strings in tabular rows",
      "input": {
        "items": [
          { "id": 1, "status": "true" },
          { "id": 2, "status": "false" }
        ]
      },
      "expected": "items[2]{id,status}:\n  1,\"true\"\n  2,\"false\"",
      "specSection": "9.3"
    },
    {
      "name": "encodes tabular arrays with keys needing quotes",
      "input": {
        "items": [
          { "order:id": 1, "full name": "Ada" },
          { "order:id": 2, "full name": "Bob" }
        ]
      },
      "expected": "items[2]{\"order:id\",\"full name\"}:\n  1,Ada\n  2,Bob",
      "specSection": "9.3"
    },
    {
      "name": "encodes tabular arrays with empty string keys",
      "input": {
        "": [
          { "id": 1, "name": "Ada" },
          { "id": 2, "name": "Bob" }
        ]
      },
      "expected": "\"\"[2]{id,name}:\n  1,Ada\n  2,Bob",
      "specSection": "9.3"
    },
    {
      "name": "quotes hash-leading string in tabular cell",
      "input": {
        "items": [{ "tag": "#a" }, { "tag": "b" }]
      },
      "expected": "items[2]{tag}:\n  \"#a\"\n  b",
      "specSection": "7.2",
      "note": "Unquoted, the first row would read as a comment line on decode"
    },
    {
      "name": "collapses a uniform nested object column into a nested field group",
      "input": {
        "orders": [
          { "id": 1, "customer": { "name": "Ada", "country": "DK" }, "total": 99 },
          { "id": 2, "customer": { "name": "Bob", "country": "UK" }, "total": 149 }
        ]
      },
      "expected": "orders[2]{id,customer{name,country},total}:\n  1,Ada,DK,99\n  2,Bob,UK,149",
      "specSection": "9.3"
    },
    {
      "name": "collapses sibling nested field groups with depth-first row layout",
      "input": {
        "shipments": [
          { "id": "s1", "sender": { "name": "ACME", "city": "Berlin" }, "receiver": { "name": "Globex", "city": "Oslo" } }
        ]
      },
      "expected": "shipments[1]{id,sender{name,city},receiver{name,city}}:\n  s1,ACME,Berlin,Globex,Oslo",
      "specSection": "9.3"
    },
    {
      "name": "collapses nested field groups recursively without a depth cap",
      "input": {
        "items": [
          { "id": 1, "geo": { "point": { "lat": 1.5, "lon": 2.5 } } },
          { "id": 2, "geo": { "point": { "lat": 3, "lon": 4 } } }
        ]
      },
      "expected": "items[2]{id,geo{point{lat,lon}}}:\n  1,1.5,2.5\n  2,3,4",
      "specSection": "9.3"
    },
    {
      "name": "uses the active delimiter inside nested field groups",
      "input": {
        "orders": [
          { "id": 1, "customer": { "name": "Ada", "country": "DK" }, "total": 99 },
          { "id": 2, "customer": { "name": "Bob", "country": "UK" }, "total": 149 }
        ]
      },
      "options": { "delimiter": "|" },
      "expected": "orders[2|]{id|customer{name|country}|total}:\n  1|Ada|DK|99\n  2|Bob|UK|149",
      "specSection": "9.3"
    },
    {
      "name": "quotes subfield names inside nested field groups per key encoding",
      "input": {
        "items": [
          { "id": 1, "customer": { "full name": "Ada", "country": "UK" } }
        ]
      },
      "expected": "items[1]{id,customer{\"full name\",country}}:\n  1,Ada,UK",
      "specSection": "9.3"
    },
    {
      "name": "falls back to list form when nested object keys differ per row",
      "input": {
        "entries": [
          { "id": 1, "meta": { "a": 1 } },
          { "id": 2, "meta": { "b": 2 } }
        ]
      },
      "expected": "entries[2]:\n  - id: 1\n    meta:\n      a: 1\n  - id: 2\n    meta:\n      b: 2",
      "specSection": "9.3",
      "note": "The meta column is not nested-uniform (differing key sets), so the whole array uses §9.4"
    },
    {
      "name": "falls back to list form when a column mixes null and objects",
      "input": {
        "orders": [
          { "id": 1, "customer": { "name": "Ada" } },
          { "id": 2, "customer": null }
        ]
      },
      "expected": "orders[2]:\n  - id: 1\n    customer:\n      name: Ada\n  - id: 2\n    customer: null",
      "specSection": "9.3",
      "note": "A null cell is a primitive, so the customer column is neither uniform-primitive nor nested-uniform"
    },
    {
      "name": "falls back to list form when a nested object contains an array",
      "input": {
        "orders": [
          { "id": 1, "customer": { "name": "Ada", "tags": ["x"] } }
        ]
      },
      "expected": "orders[1]:\n  - id: 1\n    customer:\n      name: Ada\n      tags[1]: x",
      "specSection": "9.3",
      "note": "Array values disqualify a column; rows must contain only primitive cells"
    },
    {
      "name": "falls back to list form when a nested column contains an empty object",
      "input": {
        "items": [
          { "id": 1, "meta": {} }
        ]
      },
      "expected": "items[1]:\n  - id: 1\n    meta:",
      "specSection": "9.3",
      "note": "Nested-uniform requires non-empty objects, mirroring the empty-object exclusion for elements"
    }
  ]
}