h4l
Joined 10 years ago
Joined 10 years ago
I wonder if Deno can be used with https://quarto.org/ now?
It's a good idea for a project like this. One bit of feedback is that it would be helpful to have a bit more context for the images - the titles get elipsised on mobile and when viewing a full image you can't see the title.
My immediate use case is very IO-bound, and won't use huge message sizes, so decoding/encoding performance probably isn't a huge problem. My hunch is It should be fast enough for event handling small messages, or it'd also be fine for passing binary buffers between Python and JS. (E.g using an array library like numpy and shipping an array over as a buffer, with some other JS objects for extra metadata.) (More so if I implemented reading/writing an mmap.)
https://docs.python.org/3/library/types.html#types.MappingPr...
It is, but if you already have bash, adding another shell script isn't much of a jump. e.g. I'd feel OK about committing jb to another repo for use from a .envrc file to set up an environment, whereas committing a binary would not feel good.
> Biggest crime of the Unix world probably.
Sorry if I'm perpetuating this! :) My take is that problem is not with bash, the problem is that it's hard for more advanced tools to replace it.
jb doesn't have high-level knowledge of other formats, it can read from common shell data sources, like command-line arguments, environment variables and files. It gives you ways to pull several of these sources into a single JSON object.
jb understands some simple/general formats commonly used in shell environments:
- key=value pairs (e.g. environment variable declarations, like the `env` program prints
- delimited lists, like a,b,c,d; (but any character can be the delimiter) including null-delimited (commonly used to separate lists of file paths)
- JSON itself — jb can validate and merge together arrays and objects
You can use these simple sources to build up a more complex structure, e.g. using a pipeline of other command line tools to generate null-delimited data, or envar declarations, then consuming the program's output via process substitution <(...). (See the section in the README that explains process substitution if you're not familiar, it's really powerful.)
So jb is more suited to creating ad-hoc JSON for specific tasks. If you had both jc and jb available and jc could read the source you need, you'd prefer jc.
For good measure, this is how you might do the same with jb:
$ jb Hello=world array:number[]@<(seq 10) object:json@<(date=$(date -Iseconds) jb @date)
{"Hello":"world","array":[1,2,3,4,5,6,7,8,9,10],"object":{"date":"2024-07-03T19:26:36+00:00"}}
Alternatively, using the :{} object entry syntax: jb Hello=world array:number[]@<(seq 10) object:{}=date=$(date -Iseconds)
{"Hello":"world","array":[1,2,3,4,5,6,7,8,9,10],"object":{"date":"2024-07-03T19:30:26+00:00"}}Second is situations where you'd rather not add an additional dependency, but bash is pretty much a given. For example, CI environments, scripts in dev environments, container entrypoints. Or things that area already written in bash.
I don't advocate writing massive programs in bash, for sure it's better to turn to a proper language before things get hairy. But bash is just really ubiquitous, and most people who do any UNIX work will be able to deal with a bit of shell script.
$ jb size:number=oops; echo $?
json.encode_number(): not all inputs are numbers: 'oops'
json(): Could not encode the value of argument 'size:number=oops' as a 'number' value. Read from inline value.
␘
1
If you pipe the jb error into jq, jq fails to parse the JSON (because of the Cancel ctrl char) and also errors: $ jb size:number=oops | jq
json.encode_number(): not all inputs are numbers: 'oops'
json(): Could not encode the value of argument 'size:number=oops' as a 'number' value. Read from inline value.
parse error: Invalid numeric literal at line 2, column 0
$ declare -p PIPESTATUS
declare -a PIPESTATUS=([0]="1" [1]="4")
So jq exits with status 4 here.This is just the kind of use case I had in mind. Something I've considered is publishing a mini version with only the json.encode_string function, as that's enough to create an array of JSON-encoded strings and use a hard-coded template with printf to insert the JSON string values.
That would be a fraction of the overall json.bash file size.