Skip to content
A simple JSON flattener written in Rust
Rust
Branch: master
Clone or download

Latest commit

George Robinson
George Robinson Initial commit
Latest commit bf32c00 Jul 6, 2019

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Initial commit Jul 5, 2019
.gitignore Initial commit Jul 5, 2019
.travis.yml Initial commit Jul 5, 2019
Cargo.lock Initial commit Jul 5, 2019
Cargo.toml Initial commit Jul 5, 2019
LICENSE Initial commit Jul 5, 2019
README.md Initial commit Jul 5, 2019

README.md

FlatJSON

Build Status

FlatJSON is a simple JSON flattener written in Rust. It parsers JSON, either from a file or stdin, and prints a flattened version of the JSON that is easier to search with programs such as grep.

{
    "name": "John Doe",
    "age": 43,
    "email": "john.doe@example.com",
    "phones": [
        "+44 1234567",
        "+44 2345678"
     ],
     "addresses": [{
         "number": 1,
         "street": "Borough High Street",
         "city": "London",
         "zip": "SE1 1"
     }]
}

For example, the JSON above is flattened into the following output:

.name = "John Doe"
.age = 43
.email = "john.doe@example.com"
.phones.0 = "+44 1234567"
.phones.1 = "+44 2345678"
.addresses.0.number = 1
.addresses.0.street = "Borough High Street"
.addresses.0.city = "London"
.addresses.0.zip = "SE1 1"

Usage

To run FlatJSON do cargo run. To create a release build with optimizations do cargo build --release. This is the better option if using FlatJSON rather than contributing to it.

FlatJSON can flatten JSON from either a file:

flatjson example.json

or stdin:

cat example.json | flatjson

If the file does not exist, or the JSON is not a valid JSON object then flatjson writes an error message to stderr and exits with a status code of 1.

Contributions

This project is licensed under the MIT License. Please feel free to fork it, use it for education purposes or even make contributions via Pull Requests.

You can’t perform that action at this time.