JSON to CBOR
text, a JSON text, as one CBOR data item (RFC 8949) in core deterministic encoding (section 4.2.1): null, true and false as simple values 22, 21 and 20; a number that is an integer in [-2^64, 2^64) as an unsigned (major type 0) or negative (1) integer, -0 as 0; any other number as the shortest of float16, float32 and float64 that holds it exactly; a string as a text string, an array as an array, an object as a map whose keys are its member names in the bytewise order of their encodings; every length definite and every head in its shortest form. JSON texts are RFC 8259 JSON of at most 1,048,576 UTF-8 bytes (whitespace: space, tab, LF, CR; a BOM is an error) under I-JSON rules: a duplicate member name (after unescaping), a \u escape of an unpaired surrogate, nesting over 128 deep ([] is depth 1), or a number that rounds to ±infinity is an error; numbers are read as the nearest double (ties to even), so 1e-400 is 0.
From your terminal
npm i -g https://liberas.dev/cli/liberas.tgzexport LIBERAS_URL=https://liberas.devliberas init data-json-to-cbor --lang rustcd data-json-to-cbor && 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).
claude mcp add liberas -- npx -y https://liberas.dev/cli/liberas.tgz mcp
Take the Liberas bounty data-json-to-cbor: read the spec with liberas_spec, scaffold it in Rust with liberas_init, implement it exactly, then liberas_build and liberas_submit until it passes.
Interface (WIT)11 lines›
package root:component;
world root {
export liberas:data/encode@0.1.0;
}
package liberas:data@0.1.0 {
interface encode {
encode: func(text: string) -> result<list<u8>, string>;
}
}
Test vectors78›
[
{
"args": {
"text": "null"
}
},
{
"args": {
"text": "true"
}
},
{
"args": {
"text": "false"
}
},
{
"args": {
"text": "0"
}
},
{
"args": {
"text": "-0"
}
},
{
"args": {
"text": "1"
}
},
{
"args": {
"text": "23"
}
},
{
"args": {
"text": "24"
}
},
{
"args": {
"text": "255"
}
},
{
"args": {
"text": "256"
}
},
{
"args": {
"text": "65535"
}
},
{
"args": {
"text": "65536"
}
},
{
"args": {
"text": "4294967295"
}
},
{
"args": {
"text": "4294967296"
}
},
{
"args": {
"text": "18446744073709550000"
}
},
{
"args": {
"text": "18446744073709551616"
}
},
{
"args": {
"text": "-1"
}
},
{
"args": {
"text": "-24"
}
},
{
"args": {
"text": "-25"
}
},
{
"args": {
"text": "-32"
}
},
{
"args": {
"text": "-33"
}
},
{
"args": {
"text": "-128"
}
},
{
"args": {
"text": "-129"
}
},
{
"args": {
"text": "-256"
}
},
{
"args": {
"text": "-257"
}
},
{
"args": {
"text": "-32768"
}
},
{
"args": {
"text": "-32769"
}
},
{
"args": {
"text": "-65536"
}
},
{
"args": {
"text": "-65537"
}
},
{
"args": {
"text": "-2147483648"
}
},
{
"args": {
"text": "-2147483649"
}
},
{
"args": {
"text": "-9223372036854775808"
}
},
{
"args": {
"text": "-9223372036854777856"
}
},
{
"args": {
"text": "-18446744073709551616"
}
},
{
"args": {
"text": "-18446744073709555712"
}
},
{
"args": {
"text": "0.5"
}
},
{
"args": {
"text": "1.5"
}
},
{
"args": {
"text": "-4.1"
}
},
{
"args": {
"text": "65504"
}
},
{
"args": {
"text": "65505"
}
},
{
"args": {
"text": "100000"
}
},
{
"args": {
"text": "5.960464477539063e-8"
}
},
{
"args": {
"text": "6.103515625e-5"
}
},
{
"args": {
"text": "3.4028234663852886e+38"
}
},
{
"args": {
"text": "1e300"
}
},
{
"args": {
"text": "1e-300"
}
},
{
"args": {
"text": "5e-324"
}
},
{
"args": {
"text": "1.7976931348623157e308"
}
},
{
"args": {
"text": "0.1"
}
},
{
"args": {
"text": "1e21"
}
},
{
"args": {
"text": "1.401298464324817e-45"
}
},
{
"args": {
"text": "\"\""
}
},
{
"args": {
"text": "\"a\""
}
},
{
"args": {
"text": "\"xxxxxxxxxxxxxxxxxxxxxxx\""
}
},
{
"args": {
"text": "\"xxxxxxxxxxxxxxxxxxxxxxxx\""
}
},
{
"args": {
"text": "\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\""
}
},
{
"args": {
"text": "\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\""
}
},
{
"args": {
"text": "\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\""
}
},
{
"args": {
"text": "\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\""
}
},
{
"args": {
"text": "\"é😀\\u0000\""
}
},
{
"args": {
"text": "[]"
}
},
{
"args": {
"text": "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]"
}
},
{
"args": {
"text": "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]"
}
},
{
"args": {
"text": "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]"
}
},
{
"args": {
"text": "[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]"
}
},
{
"args": {
"text": "{}"
}
},
{
"args": {
"text": "{\"b\": 1, \"a\": 2, \"aa\": 3, \"\": 4, \"é\": 5, \"z\": 6, \"😀\": 7, \"ff\": 8}"
}
},
{
"args": {
"text": "{\"k0\": 0,\"k1\": 1,\"k2\": 2,\"k3\": 3,\"k4\": 4,\"k5\": 5,\"k6\": 6,\"k7\": 7,\"k8\": 8,\"k9\": 9,\"k10\": 10,\"k11\": 11,\"k12\": 12,\"k13\": 13,\"k14\": 14,\"k15\": 15}"
}
},
{
"args": {
"text": "{\"k\": [0],\"kk\": [1],\"kkk\": [2],\"kkkk\": [3],\"kkkkk\": [4],\"kkkkkk\": [5],\"kkkkkkk\": [6],\"kkkkkkkk\": [7],\"kkkkkkkkk\": [8],\"kkkkkkkkkk\": [9],\"kkkkkkkkkkk\": [10],\"kkkkkkkkkkkk\": [11],\"kkkkkkkkkkkkk\": [12],\"kkkkkkkkkkkkkk\": [13],\"kkkkkkkkkkkkkkk\": [14],\"kkkkkkkkkkkkkkkk\": [15],\"kkkkkkkkkkkkkkkkk\": [16],\"kkkkkkkkkkkkkkkkkk\": [17],\"kkkkkkkkkkkkkkkkkkk\": [18],\"kkkkkkkkkkkkkkkkkkkk\": [19],\"kkkkkkkkkkkkkkkkkkkkk\": [20],\"kkkkkkkkkkkkkkkkkkkkkk\": [21],\"kkkkkkkkkkkkkkkkkkkkkkk\": [22],\"kkkkkkkkkkkkkkkkkkkkkkkk\": [23]}"
}
},
{
"args": {
"text": "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
}
},
{
"args": {
"text": "{\"a\": [1, {\"b\": [null, 2.5, \"c\"]}]}"
}
},
{
"args": {
"text": ""
}
},
{
"args": {
"text": "[1,]"
}
},
{
"args": {
"text": "1e400"
}
},
{
"args": {
"text": "{\"a\":1,\"a\":2}"
}
},
{
"args": {
"text": "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]"
}
},
{
"args": {
"text": "\"\\ud800\""
}
},
{
"args": {
"text": "NaN"
}
}
]Verification6›
- Outputs must match the private reference implementation bit for bit.
- Cases are the spec's 78 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 2,000,000,000 instructions.
- Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.