# little-flute

> A clarinet based json parser that can be used to parse JSON objects with duplicate keys

Latest version **0.1.1** (published 2023-05-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install little-flute
pnpm add little-flute
yarn add little-flute
bun add little-flute
```

## 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.1.1 |
| Published | 2023-05-09 |
| First published | 2023-03-27 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 34.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Jennifer Valle |
| Maintainers | jvallexm |
| Keywords | sax, json, parser, stream, streaming, event, events, emitter, async, streamer, browser |

## Links

- npm: https://www.npmjs.com/package/little-flute
- Repository: https://github.com/IBM/little-flute
- Homepage: https://github.com/IBM/little-flute#readme
- Issues: https://github.com/IBM/little-flute/issues
- npm.io page: https://npm.io/package/little-flute

## Dependencies (1)

- [clarinet](https://npm.io/package/clarinet.md) ^0.12.5

## 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.1.1 (latest) — 2023-05-09
- 0.1.2 — 2023-03-28
- 0.1.0 — 2023-03-27

## README

# little-flute

`little-flute` is a minimal dependency json parser that can be used to parse JSON objects with multiple duplicate keys.

## Example Usage

```js
const flute = require("little-flute")

new flute(
  `{
    "resource": {
      "aws_instance": {
        "example": {
          "instance_type": {
            "type": "t2.micro"
          },
          "ami": "ami-abc123"
        }
      },
      "aws_instance": {
        "example2": {
          "instance_type": {
            "type": "t2.micro"
          },
          "ami": "ami-abc123"
        }
      }
    }
  }`
).parse();
```

Returns the value :
```js
{
  "resource": {
    "aws_instance": {
      "example": {
        "instance_type": {
          "type": "t2.micro"
        },
        "ami": "ami-abc123"
      }
    },
    "aws_instance_": { // duplicate keys will have an _ appended
      "example2": {
        "instance_type": {
          "type": "t2.micro"
        },
        "ami": "ami-abc123"
      }
    }
  }
}
```

## Extensions

Users can extend the `flute` constructor before parse with callback functions. Each callback returns `currentRef`, the part of the larget object that is currently being manipluated, and `parsedJson`, the entire JSON object.

```js
const flute = require("little-flute");

let extendedFlute = new flute(
  `{
    "resource": {
      "aws_instance": {
        "example": {
          "instance_type": {
            "type": "t2.micro"
          },
          "ami": "ami-abc123"
        }
      },
      "aws_instance": {
        "example2": {
          "instance_type": {
            "type": "t2.micro"
          },
          "ami": "ami-abc123"
        }
      }
    }
  }`,
  {
    onKey: function(key, currenRef, parsedJson) {
      // edit data after a new key has been added
    },
    onValue: function(value, currenRef, parsedJson) {
      // edit data when a new value is added
    },
    onOpenObject: function(key, currenRef, parsedJson) {
      // edit data after a new object has been opened
    },
    onCloseObject: function(currenRef, parsedJson) {
      // edit data after an object is closed
    },
    onOpenArray: function(currenRef, parsedJson) {
      // edit data after a new array has been opened
    },
    onCloseArray: function(currenRef, parsedJson) {
      // edit data after an array is closed
    }
  }
)

```

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