Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/mycaule/patriarchy

Summarize JSON hierarchies only on values
https://github.com/mycaule/patriarchy

Last synced: 20 days ago
JSON representation

Summarize JSON hierarchies only on values

Awesome Lists containing this project

README

        


Render nested hierarchies based only on values


Build Status
dependencies Status
devDependencies Status


npm package
npm package
npm package




I wrote this library to pretty print JSON describing identify records. The code is inspired from [archy](https://github.com/substack/node-archy).

## Usage

You can use this as an alternative method to `JSON.stringify` when the fields name are obvious to the reader.

```javascript
console.log(JSON.stringify(obj, null, 2))
```
```
{
"name": "Katy Perry",
"description": "American singer-songwriter",
"image": {
"contentUrl": "http://t3.gstatic.com/images?q=tbn:ANd9GcQrlKFmaiEtUImNiuD_pqzHPjDcjF4yaRThSFMh-rYuB8snFUfk",
"url": "https://en.wikipedia.org/wiki/Katy_Perry"
},
"detailedDescription": {
"articleBody": "Katheryn Elizabeth Hudson, known professionally as Katy Perry, is an American singer and songwriter. After singing in church during her childhood, she pursued a career in gospel music as a teenager. ",
"url": "https://en.wikipedia.org/wiki/Katy_Perry",
"license": "https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License"
},

"url": "http://www.katyperry.com/"
}
```

#### JavaScript

```javascript
const patriarchy = require('patriarchy')
console.log(patriarchy(obj))
```
```
Katy Perry
│ American singer-songwriter
│ http://www.katyperry.com/
├─┐ http://t3.gstatic.com/images?q=tbn:ANd9GcQrlKFmaiEtUImNiuD_pqzHPjDcjF4yaRThSFMh-rYuB8snFUfk
│ │ https://en.wikipedia.org/wiki/Katy_Perry
└─┐ Katheryn Elizabeth Hudson, known professionally as Katy Perry, is an American singer and songwriter. After singing in church during her childhood, she pursued a career in gospel music as a teenager.
│ https://en.wikipedia.org/wiki/Katy_Perry
│ https://en.wikipedia.org/wiki/Wikipedia:Text_of_Creative_Commons_Attribution-ShareAlike_3.0_Unported_License
```

#### Command-line interface

Install the tool globally `npm install -g patriarchy` or use with `npx patriarchy` if this is available in your Node.js version.

```bash
$ patriarchy '{"a1": "hello", "b1": {"a2": "world", "b2": "!"}}'
hello
└─┐ world
│ !
```

## Contributions

[Changes and improvements](https://github.com/mycaule/patriarchy/wiki) are welcome! Feel free to fork and open a pull request into `master`.

### Running the tests

You can lint the code and run all unit tests using that script.
```bash
npm test
```

### License
`patriarchy` is licensed under the [Apache 2.0 License](https://github.com/mycaule/patriarchy/blob/master/LICENSE).

## References

* [James Halliday - archy package](https://github.com/substack/node-archy)