npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

jsonl-tree

v0.0.1

Published

A simple way to encode nested tree structures of JSON objects.

Downloads

26

Readme

jsonl-tree

A simple way to encode nested tree structures of JSON objects.

Similar to the way languages such as YAML and Python indent for scope, jsonl-tree extends the jsonl spec slightly to allow easy construction of trees of the individual JSON objects.

Consider a JSON object that describes a person where you might have a field such as "children": [] that nests recursively. It can get unwieldy to construct even a few levels of a tree of such objects and and unreadable to read when you try to actually nest the structures to conform to regular JSON.

With jsonl-tree you instead just use jsonl (newline separated JSON) but with the additional feature that there is leading whitespace indenting a child object.

As an example, this JSON object describing 4 generations of a part of a family tree:

{
  "name": "Rheia",
  "age": 100,
  "children": [
    {
      "name": "Zeus",
      "age": 70,
      "children": [
        {
          "name": "Ares",
          "age": 50,
          "children": [
            {
              "name": "Eros",
              "age": 25
            },
            {
              "name": "Phobos",
              "age": 20
            }
          ]
        },
        {
          "name": "Hebe",
          "age": 45
        }
      ]
    }
  ]
}

would simply become:

// nest=children
{"name": "Rheia", "age": 100}
  {"name": "Zeus", "age": 70}
    {"name": "Ares", "age": 50}
      {"name": "Eros", "age": 25}
      {"name": "Phobos", "age": 20}
    {"name": "Hebe", "age": 45}

If you save the above to a file family.txt When you run cat family.txt | jsonl-tree it will expand the jsonl-tree representation into the actual JSON with the nested objects built together. The // nest=children comment tells the jsonl-tree compiler to use the field name children for nesting the objects.

Note that the compiler also accepts the following syntax that will generate the same JSON. This is used to further compress the leading whitespace if necessary by using a leading int on each line specifying the nesting level:

// nest=children
0{"name": "Rheia", "age": 100}
1{"name": "Zeus", "age": 70}
2{"name": "Ares", "age": 50}
3{"name": "Eros", "age": 25}
3{"name": "Phobos", "age": 20}
2{"name": "Hebe", "age": 45}

This is obviously not very human readable at all and is only intended to be used as an intermediate representation that is output by other software tools.

Note that currently jsonl-tree only handles the nesting of objects by way of a single field name.

Installation

npm i jsonl-tree

Testing

npm test