# gatsby-transformer-json-key-value-to-array

> Gatsby transformer plugin for JSON key-value files

Latest version **0.0.1** (published 2018-10-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install gatsby-transformer-json-key-value-to-array
pnpm add gatsby-transformer-json-key-value-to-array
yarn add gatsby-transformer-json-key-value-to-array
bun add gatsby-transformer-json-key-value-to-array
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.1 |
| Published | 2018-10-25 |
| First published | 2018-10-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Bojan Mihelac |
| Maintainers | bmihelac |
| Keywords | gatsby, gatsby-plugin, json |

## Links

- npm: https://www.npmjs.com/package/gatsby-transformer-json-key-value-to-array
- Repository: https://github.com/bmihelac/gatsby-transformer-json-key-value-to-array
- Issues: https://github.com/bmihelac/gatsby-transformer-json-key-value-to-array/issues
- npm.io page: https://npm.io/package/gatsby-transformer-json-key-value-to-array

## Dependencies (1)

- [@babel/runtime](https://npm.io/package/@babel/runtime.md) ^7.1.2

## 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

- 0.0.1 (latest) — 2018-10-25

## README

# gatsby-transformer-json-key-value-to-array

[![Build Status](https://travis-ci.com/bmihelac/gatsby-transformer-json-key-value-to-array.svg?branch=master)](https://travis-ci.com/bmihelac/gatsby-transformer-json-key-value-to-array)

Transforms JSON objects into queryable array with key/value pairs.

## Install

`npm install --save gatsby-transformer-json-key-value-to-array`

If you want to transform json files, you also need to have `gatsby-source-filesystem` installed and configured so it
points to your files.

## How to use

In your `gatsby-config.js`:

```javascript
module.exports = {
  plugins: [
    `gatsby-transformer-json-key-value-to-array`,
    {
      resolve: `gatsby-source-filesystem`,
      options: {
        path: `./src/data/`,
      },
    },
  ],
}
```

## Parsing algorithm

It recognizes files with `application/json` media type.

Each key/value is parsed into Node of type `KeyValue` with following fields:

* `key` - original key
* `value` - original value if it is string, otherwise JSON value of original value
* `isJson` - boolean field indicates if original value is JSON
* `file` - foreign key to source file (to allow filtering)

## Examples

If your project has a `en.json` with

```json
{ "title": "My title",  "description": "Lorem ipsum" }
```

Then the following two nodes would be created:

```json
[
  {
    "key": "title",
    "value": "My title",
    ...
  },
  {
    "key": "description",
    "value": "Lorem ipsum",
    ...
  }
]
```

Query example that will return all items with key starting with `title`:

```graphql
{
  allKeyValue(filter: {key:{regex: "/^title/"}}) {
    edges {
      node {
        key
        value
      }
    }
  }
}
```

Returns:

```json
{
  "data": {
    "allKeyValue": {
      "edges": [
        {
          "node": {
            "key": "title",
            "value": "My title"
          }
        }
      ]
    }
  }
}
```

---
_Source: https://npm.io/package/gatsby-transformer-json-key-value-to-array · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
