Skip to content
/ jsonflat Public

Converts json to flat form, by prefixing each field by path

Notifications You must be signed in to change notification settings

krdln/jsonflat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Jsonflat

Jsonflat is a utility to convert JSONs into flatter, greppable form. Given the following json:

{
    "foos": [
        {
            "name": "a",
            "frobnicity": 50
        },
        {
            "name": "b",
            "frobnicity": 50
        }
    ]
}

it spits out:

.foos[0](name=a).frobnicity: 50
.foos[0](name=a).name: "a"
.foos[1](name=b).frobnicity: 50
.foos[1](name=b).name: "b"

Note that name key is special and is included in paths. This is to make paths more meaningful if your data representation is not a dict, but rather list of named objects.

It also works when jsons are embedded in plaintext:

[2020-02-02 20:02] Got response: {
    "code": 404,
    "message": "nothing there"
}. Ignoring.
[2020-02-02 20:02] Got response: .code: 404
[2020-02-02 20:02] Got response: .message: "nothing there"
[2020-02-02 20:02] Got response: {…}. Ignoring.

Usage

Reads from stdin, writes to stdout.

Example

command that returns json | jsonflat | grep "thing"

There's also a stripcommonprefix command included that should help with long paths:

command that returns json | jsonflat | grep "thing" | stripcommonprefix

Installation

Linux

Check out the releases.

Manual

  1. Install Rust
  2. cargo install --git https://github.com/krdln/jsonflat

License

TODO

About

Converts json to flat form, by prefixing each field by path

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages