Goodbye, cw-json! Hello, kPointer!

I have supplanted cw-json, replacing it with a new library, kPointer. The concept is the same, and porting from cw-json to kPointer is fairly straightforward. However, I realized that I made a key mistake when I started cw-json: thinking that I was only dealing with JSON.

(naming things is hard)

More Object Types

kPointer not only supports extracting values from JSON by means of JSON Pointer paths, as cw-json did. kPointer also supports YAML (by way of yamlkt) and HTML/XML (by way of Ksoup).

All get wrapped by an adapter-style abstraction layer, and you can make custom adapters to support other object tree structures. Part of the reason for supporting YAML, HTML, and XML was to exercise the abstraction layer. I am a firm believer in the “rule of 3” when it comes to APIs, frameworks, and abstraction layers: you need at least 3 separate implementations to feel comfortable that what you have will be able to handle more beyond those 3.

If you happen to want to adapt other structures, there is a conformance test suite that you can leverage as the basis for your own tests to see if your implementation covers all the cases. Personally, I am anticipating adding support for other data structures in the not-too-distant future.

A Better “Dot Notation” Option

The final release of cw-json, 0.4.0, introduced support for an ad-hoc sort of “dot notation” syntax, alongside JSON Pointer and its kin (relative JSON Pointer, JSON Pointer fragment syntax). “Dot notation” was aiming at the syntax that you see in template languages like Handlebars or Mustache, such as foo.bar.goo, to navigate into an object graph.

kPointer replaces that ad-hoc dot notation with… well, OK, a better ad-hoc dot notation, what I’m calling JavaScript access path notation. This is pretty much a clean superset of the original dot notation, but also supports bracket syntax (e.g., foo['bar'] or foo[0]).

Porting Support

Since I am anticipating porting kPointer to other languages in the future, I have a fairly extensive conformance suite, as part of broader support for porting kPointer.

kPointer comes with a CLI designed for running the conformance suite, and ports could create their own workalike CLI to assist in testing.

A Dedicated Site

Whereas cw-json had a long README and not much more, kPointer has a dedicated site, with lots of information on using the libraries and more.

What’s Next?

As I mentioned earlier, I expect to be adding support for more data format parsers, covering more data formats. For example, I expect to be adding support for CSV and similar delimited file formats.

It’s possible that I will add more pointer syntaxes besides the flavors of JSON Pointer and JavaScript access paths. I do not have any current plans in that area, but, hey, plans change.