JSON2CBOR(1)
π json2cbor(1) β the manual page, but make it cute π
okay bestie, gather round, because today we're talking about json2cbor, a lil command from the json2cbor(1) manual, and honestly? it's giving β¨glow-up for your JSONβ¨
πΈ NAME πΈ
json2cbor β convert JSON formatted text to CBOR π¦
no cap, that's the whole job. JSON in, CBOR out, slay.
β¨ SYNOPSIS β¨
json2cbor test.json > test.cbor
that's it. that's the vibe. redirect it into a file and go live your life π
π DESCRIPTION π
so here's the tea: json2cbor spits out a CBOR data stream for whatever set of input files you hand it. and those files can be one of two things, bestie:
- a single JSON item, simple, lowkey iconic π
- or an RFC 7464 encoded JSON text series β that's over at https://tools.ietf.org/html/rfc7464 if you wanna read the lore
and in that second case? every JSON item kicks off with the byte "1e" (hex), which is "30" (dec), aka the "Record Separator" (RS), and then it wraps up with a newline. periodt.
an example sequence, for the visual learners:
β{"d":"2014-09-22T21:58:35.270Z","value":6}
β{"d":"2014-09-22T21:59:15.117Z","value":12}
and if you're sitting there like "okay but how do I make one of these" β you can generate a sequence like this from a newline-separated JSON file, like so:
sed -e s/^/\x1e/g [FILE]
note: your shell might need$''around thesedpattern to actually work. the author said they'll look for a more shell-inspecific way of encdoding this later π (their typo, not mine, keeping it π)
now, why is the author making you go through this pain? because more of your JSON items have newlines embedded in them than you think. i know. i know. π
ideally you'd write your files out using RFC 7464, and then you'd also get some of the benefits of that format, including:
- Detect a truncated file due to a process dying in the middle of writing your data π₯
- Recovery while parsing from such a truncated file that was later appended to πͺ
- Detect when multiple processes are writing to the same file in an uncoordinated way π
- Maintain newlines in your JSON. They'll sneak in there anyway π«Ά
the newlines are inevitable. respect the newlines. π§
π OPTIONS π
-:β read from stdin instead of a file. This is the default. (yes, the flag is literally a colon. main character energy.)-c,--canonicalβ Canonical output π-x,--hexβ output a hex-encoded version of the CBOR data, instead of the native CBOR data π-V,--versionβ print the node-cbor version and exit β-h,--helpβ print some help text and exit π
π₯ SEE ALSO π₯
- node-cbor β https://github.com/hildjj/node-cbor π¦
- RFC 8949 β https://www.rfc-editor.org/rfc/rfc8949.html π
and that's the whole page, bestie!! this was JSON2CBOR(1), dated November 2022, and honestly? iconic. go convert something. mwah ππ
β¨
π¦ where this page comes from
- ubuntu noble: node-cbor 8.1.0+dfsg+~cs5.2.1-3 Β· MIT
- ubuntu resolute: node-cbor 8.1.0+dfsg+~cs5.2.1-3 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms