JSON2CBOR(1)

πŸ“¦
version 8.1.0 Β· 3 versions
, in ubuntu noble, ubuntu resolute

πŸ’– 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:

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 the sed pattern 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 πŸ”₯


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