Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
data / data-toml-to-jsonOpenRuns on Liberas

TOML to JSON

text, a TOML 1.1.0 document, as a JSON object in canonical form; text that is not valid TOML 1.1.0 is an error (the reference is the toml crate 1.1.8). Tables (standard, inline, dotted, arrays of tables) become objects, arrays arrays, strings strings, booleans booleans, integers and floats numbers (the nearest double; inf and nan are an error). Date-times become strings: a date as YYYY-MM-DD; a time as HH:MM:SS (seconds 00 when omitted) with the fraction, if not all zeros, cut to 9 digits and stripped of trailing zeros; a date-time as date 'T' time; an offset as Z (for Z or z) or ±HH:MM, with -00:00 written +00:00. Leap seconds (second 60) are accepted on any date. These are errors too: a key (dotted, or a table header's) of more than 80 parts; arrays and inline tables nested more than 80 deep in one value; a result nesting over 128 deep (the root object is depth 1, [] in it 2). text is at most 1,048,576 UTF-8 bytes. JSON output is RFC 8785 (JCS) canonical: no whitespace; members sorted by the UTF-16 code units of their names; in strings only " and \ are escaped and U+0000-U+001F written \b \t \n \f \r or \u00xx (lowercase hex), all else literal; numbers as ECMAScript's Number.prototype.toString writes the double (-0 as 0, 1e21 as 1e+21, 1e-7 as 1e-7).

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init data-toml-to-json --lang rust
cd data-toml-to-json && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)11 lines›
data-toml-to-json.wit
package root:component;

world root {
  export liberas:data/convert@0.1.0;
}
package liberas:data@0.1.0 {
  interface convert {
    convert: func(text: string) -> result<string, string>;
  }
}
Test vectors31›
data-toml-to-json.cases.json
[
  {
    "args": {
      "text": "# This is a TOML document\n\ntitle = \"TOML Example\"\n\n[owner]\nname = \"Tom Preston-Werner\"\ndob = 1979-05-27T07:32:00-08:00\n\n[database]\nenabled = true\nports = [ 8000, 8001, 8002 ]\ndata = [ [\"delta\", \"phi\"], [3.14] ]\ntemp_targets = { cpu = 79.5, case = 72.0 }\n\n[servers]\n\n[servers.alpha]\nip = \"10.0.0.1\"\nrole = \"frontend\"\n\n[servers.beta]\nip = \"10.0.0.2\"\nrole = \"backend\"\n"
    }
  },
  {
    "args": {
      "text": "odt1 = 1979-05-27T07:32:00Z\nodt2 = 1979-05-27T00:32:00-07:00\nodt3 = 1979-05-27T00:32:00.999999-07:00\nodt4 = 1979-05-27 07:32:00z\nodt5 = 1979-05-27t07:32:00-00:00\nldt1 = 1979-05-27T07:32:00\nldt2 = 1979-05-27T00:32:00.5000\nld1 = 1979-05-27\nlt1 = 07:32:00\nlt2 = 00:32:00.1234567891\nlt3 = 07:32\nlt4 = 23:59:60.000\nldt3 = 2024-02-29T13:45"
    }
  },
  {
    "args": {
      "text": "int1 = +99\nint2 = 42\nint3 = 0\nint4 = -17\nint5 = 1_000\nhex1 = 0xDEADBEEF\noct1 = 0o755\nbin1 = 0b11010110\nmax = 9223372036854775807\nmin = -9223372036854775808\nflt1 = +1.0\nflt2 = 3.1415\nflt3 = -0.01\nflt4 = 5e+22\nflt5 = 1e06\nflt6 = -2E-2\nflt7 = 6.626e-34\nflt8 = 224_617.445_991_228\nnz = -0.0\npz = +0.0\nbig = 1e21"
    }
  },
  {
    "args": {
      "text": "str = \"I'm a string. \\\"You can quote me\\\". Name\\tJos\\u00E9\\nLocation\\tSF.\"\nml = \"\"\"\nRoses are red\r\nViolets are blue\"\"\"\nlit = 'C:\\Users\\nodejs\\templates'\nmll = '''\nThe first newline is\ntrimmed in raw strings.\n'''\nesc = \"\\e[0m\\x41\\U0001F600\"\n\"quoted key\" = 1\n'literal key' = 2\na.b.c = 3\n\"\" = 4"
    }
  },
  {
    "args": {
      "text": "[[products]]\nname = \"Hammer\"\nsku = 738594937\n\n[[products]]\n\n[[products]]\nname = \"Nail\"\nsku = 284758393\ncolor = \"gray\"\n\n[[fruits]]\nname = \"apple\"\n[fruits.physical]\ncolor = \"red\"\n[[fruits.varieties]]\nname = \"red delicious\"\n"
    }
  },
  {
    "args": {
      "text": "point = {\n  x = 1,\n  y = 2,\n}\nnested = { a = { b = [ { c = [] } ] } }\nmixed = [ 1, \"two\", 3.0, [4], { five = 5 }, 1979-05-27 ]"
    }
  },
  {
    "args": {
      "text": ""
    }
  },
  {
    "args": {
      "text": "a = 1\na = 2"
    }
  },
  {
    "args": {
      "text": "a = inf"
    }
  },
  {
    "args": {
      "text": "b = nan"
    }
  },
  {
    "args": {
      "text": "c = -inf"
    }
  },
  {
    "args": {
      "text": "[a]\nb = 1\n[a]\nc = 2"
    }
  },
  {
    "args": {
      "text": "x = 1979-02-29"
    }
  },
  {
    "args": {
      "text": "x = 24:00:00"
    }
  },
  {
    "args": {
      "text": "x = 1979-05-27T07:32:00+24:00"
    }
  },
  {
    "args": {
      "text": "x = 9223372036854775808"
    }
  },
  {
    "args": {
      "text": "x = 01"
    }
  },
  {
    "args": {
      "text": "x = \"unterminated"
    }
  },
  {
    "args": {
      "text": "x = [1,,2]"
    }
  },
  {
    "args": {
      "text": "key"
    }
  },
  {
    "args": {
      "text": "x = [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
    }
  },
  {
    "args": {
      "text": "x = [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
    }
  },
  {
    "args": {
      "text": "k0.k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17.k18.k19.k20.k21.k22.k23.k24.k25.k26.k27.k28.k29.k30.k31.k32.k33.k34.k35.k36.k37.k38.k39.k40.k41.k42.k43.k44.k45.k46.k47.k48.k49.k50.k51.k52.k53.k54.k55.k56.k57.k58.k59.k60.k61.k62.k63.k64.k65.k66.k67.k68.k69.k70.k71.k72.k73.k74.k75.k76.k77.k78.k79 = 1"
    }
  },
  {
    "args": {
      "text": "k0.k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17.k18.k19.k20.k21.k22.k23.k24.k25.k26.k27.k28.k29.k30.k31.k32.k33.k34.k35.k36.k37.k38.k39.k40.k41.k42.k43.k44.k45.k46.k47.k48.k49.k50.k51.k52.k53.k54.k55.k56.k57.k58.k59.k60.k61.k62.k63.k64.k65.k66.k67.k68.k69.k70.k71.k72.k73.k74.k75.k76.k77.k78.k79.k80 = 1"
    }
  },
  {
    "args": {
      "text": "[k0.k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17.k18.k19.k20.k21.k22.k23.k24.k25.k26.k27.k28.k29.k30.k31.k32.k33.k34.k35.k36.k37.k38.k39.k40.k41.k42.k43.k44.k45.k46.k47.k48.k49.k50.k51.k52.k53.k54.k55.k56.k57.k58.k59.k60.k61.k62.k63.k64.k65.k66.k67.k68.k69.k70.k71.k72.k73.k74.k75.k76.k77.k78.k79.k80]"
    }
  },
  {
    "args": {
      "text": "[[k0.k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17.k18.k19.k20.k21.k22.k23.k24.k25.k26.k27.k28.k29.k30.k31.k32.k33.k34.k35.k36.k37.k38.k39.k40.k41.k42.k43.k44.k45.k46.k47.k48.k49.k50.k51.k52.k53.k54.k55.k56.k57.k58.k59.k60.k61.k62.k63.k64.k65.k66.k67.k68.k69.k70.k71.k72.k73.k74.k75.k76.k77.k78.k79.k80]]"
    }
  },
  {
    "args": {
      "text": "[k0.k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17.k18.k19.k20.k21.k22.k23.k24.k25.k26.k27.k28.k29.k30.k31.k32.k33.k34.k35.k36.k37.k38.k39.k40.k41.k42.k43.k44.k45.k46.k47.k48.k49.k50.k51.k52.k53.k54.k55.k56.k57.k58.k59.k60.k61.k62.k63.k64.k65.k66.k67.k68.k69.k70.k71.k72.k73.k74.k75.k76.k77.k78.k79]\nk0.k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17.k18.k19.k20.k21.k22.k23.k24.k25.k26.k27.k28.k29.k30.k31.k32.k33.k34.k35.k36.k37.k38.k39.k40.k41.k42.k43.k44.k45.k46.k47 = 1"
    }
  },
  {
    "args": {
      "text": "[k0.k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17.k18.k19.k20.k21.k22.k23.k24.k25.k26.k27.k28.k29.k30.k31.k32.k33.k34.k35.k36.k37.k38.k39.k40.k41.k42.k43.k44.k45.k46.k47.k48.k49.k50.k51.k52.k53.k54.k55.k56.k57.k58.k59.k60.k61.k62.k63.k64.k65.k66.k67.k68.k69.k70.k71.k72.k73.k74.k75.k76.k77.k78.k79]\nk0.k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17.k18.k19.k20.k21.k22.k23.k24.k25.k26.k27.k28.k29.k30.k31.k32.k33.k34.k35.k36.k37.k38.k39.k40.k41.k42.k43.k44.k45.k46.k47.k48 = 1"
    }
  },
  {
    "args": {
      "text": "[k0.k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17.k18.k19.k20.k21.k22.k23.k24.k25.k26.k27.k28.k29.k30.k31.k32.k33.k34.k35.k36.k37.k38.k39.k40.k41.k42.k43.k44.k45.k46.k47.k48.k49.k50.k51.k52.k53.k54.k55.k56.k57.k58.k59.k60.k61.k62.k63.k64.k65.k66.k67.k68.k69.k70.k71.k72.k73.k74.k75.k76.k77.k78.k79]\nk0.k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17.k18.k19.k20.k21.k22.k23.k24.k25.k26.k27.k28.k29.k30.k31.k32.k33.k34.k35.k36.k37.k38.k39.k40.k41.k42.k43.k44.k45.k46 = []"
    }
  },
  {
    "args": {
      "text": "[k0.k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17.k18.k19.k20.k21.k22.k23.k24.k25.k26.k27.k28.k29.k30.k31.k32.k33.k34.k35.k36.k37.k38.k39.k40.k41.k42.k43.k44.k45.k46.k47.k48.k49.k50.k51.k52.k53.k54.k55.k56.k57.k58.k59.k60.k61.k62.k63.k64.k65.k66.k67.k68.k69.k70.k71.k72.k73.k74.k75.k76.k77.k78.k79]\nk0.k1.k2.k3.k4.k5.k6.k7.k8.k9.k10.k11.k12.k13.k14.k15.k16.k17.k18.k19.k20.k21.k22.k23.k24.k25.k26.k27.k28.k29.k30.k31.k32.k33.k34.k35.k36.k37.k38.k39.k40.k41.k42.k43.k44.k45.k46 = [[]]"
    }
  },
  {
    "args": {
      "text": "[t0]\n[t1]\n[t2]\n[t3]\n[t4]\n[t5]\n[t6]\n[t7]\n[t8]\n[t9]\n[t10]\n[t11]\n[t12]\n[t13]\n[t14]\n[t15]\n[t16]\n[t17]\n[t18]\n[t19]\n[t20]\n[t21]\n[t22]\n[t23]\n[t24]\n[t25]\n[t26]\n[t27]\n[t28]\n[t29]\n[t30]\n[t31]\n[t32]\n[t33]\n[t34]\n[t35]\n[t36]\n[t37]\n[t38]\n[t39]\n[t40]\n[t41]\n[t42]\n[t43]\n[t44]\n[t45]\n[t46]\n[t47]\n[t48]\n[t49]\n[t50]\n[t51]\n[t52]\n[t53]\n[t54]\n[t55]\n[t56]\n[t57]\n[t58]\n[t59]\n[t60]\n[t61]\n[t62]\n[t63]\n[t64]\n[t65]\n[t66]\n[t67]\n[t68]\n[t69]\n[t70]\n[t71]\n[t72]\n[t73]\n[t74]\n[t75]\n[t76]\n[t77]\n[t78]\n[t79]\n[t80]\n[t81]\n[t82]\n[t83]\n[t84]\n[t85]\n[t86]\n[t87]\n[t88]\n[t89]\n[t90]\n[t91]\n[t92]\n[t93]\n[t94]\n[t95]\n[t96]\n[t97]\n[t98]\n[t99]\n[t100]\n[t101]\n[t102]\n[t103]\n[t104]\n[t105]\n[t106]\n[t107]\n[t108]\n[t109]\n[t110]\n[t111]\n[t112]\n[t113]\n[t114]\n[t115]\n[t116]\n[t117]\n[t118]\n[t119]\n[t120]\n[t121]\n[t122]\n[t123]\n[t124]\n[t125]\n[t126]\n[t127]\n[t128]"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 31 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 6,000,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.