# jmeta

> JSON metadata generator, outputs lodash compatible get/set strings

Latest version **1.1.0** (published 2022-01-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install jmeta
pnpm add jmeta
yarn add jmeta
bun add jmeta
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.0 |
| Published | 2022-01-28 |
| First published | 2019-11-05 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 29.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Stefan Woskowiak |
| Maintainers | swoskowiak |
| Keywords | json, map, meta, metadata, paths, keys, lodash |

## Links

- npm: https://www.npmjs.com/package/jmeta
- Repository: https://github.com/SWoskowiak/jMeta
- Homepage: https://github.com/SWoskowiak/jMeta#readme
- Issues: https://github.com/SWoskowiak/jMeta/issues
- npm.io page: https://npm.io/package/jmeta

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.15

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 1.1.0 (latest) — 2022-01-28
- 1.0.6 — 2019-11-05
- 1.0.5 — 2019-11-05
- 1.0.4 — 2019-11-05
- 1.0.3 — 2019-11-05
- 1.0.2 — 2019-11-05
- 1.0.1 — 2019-11-05
- 1.0.0 — 2019-11-05

## README

# jMeta [![Build Status](https://travis-ci.com/SWoskowiak/jMeta.svg?branch=master)](https://travis-ci.com/SWoskowiak/jMeta) ![Coverage Status](https://coveralls.io/repos/github/SWoskowiak/jMeta/badge.svg?branch=master)

A JSON mapping utility to help generate meta data of a JSON object. Maps depth and paths to found keys.

Generated paths are compatible with Lodash's `_.get` and `_.set` to help manipulate deep data sets.

The generated data is in an accessible `Map` object which you can run generator functions over as necessary or use the built in keys() and paths() to retrieve information in a more familiar way.

## Install

`npm install jmeta` or `yarn add jmeta`

## Basic Usage
```javascript
  const JMeta = require('jmeta')
  const _ = require('lodash')

  const data = {
    a: {
      b: {
        c: [
          [ { d: true }, 'ignored', { a: 'duplicate' } ]
        ]
      }
    }
  }
  const jmeta = new JMeta(data)

  console.log(jmeta.paths())     // Outputs: [ 'a', 'a.b.c[0][2].a', 'a.b', 'a.b.c', 'a.b.c[0][0].d' ]
  console.log(jmeta.keys())      // Outputs: [ 'a', 'b', 'c', 'd' ] NOTE: Unique keys
  console.log(jmeta.size)        // Outputs: 5 (NOTE: Accounts for duplicate found keys)
  console.log(jmeta.duplicates)  // Outputs: [ 'a' ]

  let foo = _.get(data, jmeta.paths()[1]) // 'a.b.c[0][2].a'
  console.log(foo)                        // Outputs: 'duplicate'

  // Access the map object directly
  console.log(jmeta.map.get('a')) // Outputs: [ { depth: 1, path: 'a' }, { depth: 6, path: 'a.b.c[0][2].a' } ]

  // You also have the option to get only the "leaves" of the tree. This will return all the final paths and not their connecting branches to them.
  const jmeta = new JMeta(data, { finalPathsOnly: true })

  console.log(jmeta.paths()) // Outputs [ 'a.b.c[0][0].d', 'a.b.c[0][2].a' ]
```

## Paths()
Takes an options object as its only parameter to specify some basic filtering.
The options object supports the following filters:
`{ depth: <number>, includes: <string>, key: <string> }`.
Filtering options can be combined in any way to reduce results accordingly.

NOTE: Paths() will always return an array, on no results found the return will simply be an empty array `[]`.
#### Filtering Paths
```javascript
  const JMeta = require('jmeta')
  const _ = require('lodash')

  const data = {
    location: {
      france: [ { name: 'Tom' }, { name: 'Mary' } ],
      italy: [ { name: 'Mike' } ]
    }
  }
  const jmeta = new JMeta(data)

  // DEPTH FILTERING
  console.log(jmeta.paths({ depth: 2 })) // Outputs: ['location.france', 'location.italy']
  console.log(jmeta.paths({ depth: 4 })) // Outputs: ['location.france[0].name', 'location.france[1].name', 'location.italy[0].name']

  // PATH INCLUDES FILTERING
  console.log(jmeta.paths({ includes: 'france' }))    // Outputs: ['location.france', 'location.france[0].name', 'location.france[1].name']
  console.log(jmeta.paths({ includes: 'france[0]' })) // Outputs: ['location.france[0].name']

  // KEY FILTERING
  console.log(jmeta.paths({ key: 'france' })) // Outputs: ['location.france']
  console.log(jmeta.paths({ key: 'name' })  // Outputs: ['location.france[0].name', 'location.france[1].name', 'location.italy[0].name']

```
## Keys()
Takes an options object as its only parameter to specify some basic filtering The options object supports the following filters:
`{ depth: <number> }`.

```javascript
  const JMeta = require('jmeta')
  const _ = require('lodash')

  const data = {
    location: {
      france: [ { person: 'Tom' }, { person: 'Mary' } ],
      italy: [ { person: 'Mike' } ]
    }
  }
  const jmeta = new JMeta(data)

  console.log(jmeta.keys())               // Outputs: [ 'location', 'france', 'person', 'italy' ] NOTE: Returns unique found keys only
  console.log(jmeta.keys({ depth: 2 }))   // Outputs: [ 'france', 'italy' ]
  console.log(jmeta.keys({ depth: 4 }))   // Outputs: [ 'person' ]

```

---
_Source: https://npm.io/package/jmeta · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
