Drop #512 (2024-08-07): The One With All The JSON Resources

janice; json.bash; TickTick

We’ve got one super new, and super useful tool, and two others I just had to include, as they both involve JSON and Bash (two of my favs)


TL;DR

(This is an AI-generated summary of today’s Drop using Sonnet via Perplexity.)

Here’s a concise three-bullet summary of the blog post:

  • Janice (https://github.com/ErikKalkoken/janice): A cross-platform desktop app for navigating and exploring large, complex JSON files with an intuitive tree structure interface and search capabilities.
  • json.bash (https://github.com/h4l/json.bash): A command-line tool and Bash library for creating JSON structures using native Bash syntax, featuring explicit typing and error handling through “Stream Poisoning.”
  • TickTick (https://github.com/kristopolous/TickTick): A Bash library that transforms JSON into Bash variables, allowing direct manipulation of JSON data within Bash scripts using a special double-backtick operator.

janice

Photo by RealToughCandy.com on Pexels.com

I suspect many of y’all work with JSON, and some of you may even work with the same kinds of gnarly nested, giant JSON that I have to on the regular. Most JSON viewers do a fairly terrible job at letting one load and explore these data files, but it looks like there may be a new tool on the block to help us out.

Janice is a fairly new entry into this space with the singular goal of helping us navigate extensive JSON files. It’s a cross-platform desktop app built with Go and Fyne.

Once you load up a JSON, you see a pretty intuitive tree structure navigation pane. In it, we can just browse through complex JSON documents. Unlike most other viewers that cry out in pain when you load up a giant JSON, janice doesn’t even break a sweat.

The search support could use some love, though, since we can def search for specific keys and values within a document (it has some support for wildcard notation), but it doesn’t support jq filters. Don’t get me wrong, the search is still useful/handy.

Oh, and it supports dark/light mode.

macOS folk will need to do the

sudo /usr/bin/xattr -d com.apple.quarantine Janice.app

dance to get it to work.


json.bash

Photo by RealToughCandy.com on Pexels.com

json.bash is a command-line tool and Bash library that creates JSON structures using native Bash syntax. Its primary function is to transform shell-native data, such as environment variables, files, and program outputs, into well-formed JSON. This capability proves invaluable for scenarios where ad-hoc JSON generation is required or when data needs to be bundled for sharing or transfer.

The design philosophy for the tool is focused on taking advantage of existing shell knowledge and integrating seamlessly with command-line utilities. It sort of a bridge between the text-based world of shell scripting and the structured data universe of JSON, without requiring external dependencies beyond Bash itself.

One of the more notable features is its type system. While Bash typically deals with strings, json.bash introduces explicit typing for JSON values. This approach improves data integrity and can help prevent common errors associated with implicit type coercion. We can specify types such as numberboolean, or null, providing a level of control often absent in shell-based JSON generation.

It even has a pretty cool error handling mechanism they call “Stream Poisoning.” This technique propagates errors through nested json.bash calls by emitting a specific control character, ensuring that downstream JSON consumers detect failures without requiring explicit exit status checks. This clever approach helps with the reliability of complex JSON generation pipelines.

While Bash might seem an unlikely choice for JSON encoding, this tool/library has oddly decent performance for basic use cases. It was designed to minimize subshell forking and has many optimizations around string operations.

The project’s documentation is comprehensive, with detailed explanations of its features, security considerations, and performance characteristics. As such, there are sufficient examples, there, to warrant shunting you to the repo vs. reproduce them here.


TickTick

Photo by Pixabay on Pexels.com

A more dangerous cousin to the tool in the middle section is TickTick. It’s is a Bash library that you source at the top of scripts to transform JSON into Bash variables. O_O

It provides a special double-backtick operator to work with JSON data that you either craft directly in Bash, or read in from a file or URL. And, it uses pure Bash to tokenize JSON strings! So, it transforms something like:

{"name": "John", "age": 30, "is_student": false}

into this string sequence:

`{`, `"name"`, `:`, `"John"`, `,`, `"age"`, `:`, `30`, `,`, `"is_student"`, `:`, `false`, `}`

then, from the logic in the script, the parser would:

  • start with { and looks for key-value pairs.
  • Reads "name", expects :, then reads "John" and stores the pair in the environment
  • Continues with "age", expects :, reads 30 and do the same.
  • Lastly, "is_student", expects :, reads false and do the same
  • Ends with }.

Lather/rinse/repeat for arrays (it’s a bit more complicated for those though).

Here’s a quick example (the README has many good ones, too):

. ${HOME}/bin/ttk

``obj = { "foo": "bar", "baz": "qux" }``

echo ``obj["foo"]``
bar

echo ``obj.baz``

qux

It comes with some helper functions:

  • tickParse – parse inline JSON (or JSON you read from a file/URL)
  • tickVars – see the current values defined in the TickTick universe
  • tickReset – clear all the currently defined variables

and is, overall, a pretty neat project.

I’m not sure I’d rely on it in production, but it could come in handy in a pinch, especially in places where you can’t add something like jq to the local stack.


FIN

Remember, you can follow and interact with the full text of The Daily Drop’s free posts on Mastodon via @dailydrop.hrbrmstr.dev@dailydrop.hrbrmstr.dev ☮️

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.