Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
data / data-json-to-msgpackOpenRuns on Liberas

JSON to MessagePack

text, a JSON text, as one MessagePack value (the MessagePack specification, 2017), each part in its shortest form: null, false and true as nil, false and true; a number that is an integer in [0, 2^64) as positive fixint, uint 8, 16, 32 or 64, -0 as 0; an integer in [-2^63, 0) as negative fixint, int 8, 16, 32 or 64; any other number as float 64; a string as fixstr, str 8, 16 or 32; an array as fixarray, array 16 or 32; an object as fixmap, map 16 or 32, its members in the order of the UTF-16 code units of their names. 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

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init data-json-to-msgpack --lang rust
cd data-json-to-msgpack && 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-json-to-msgpack.wit
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›
data-json-to-msgpack.cases.json
[
  {
    "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 1,500,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.