# json-fusion

> Json-Fusion is a Node.js library designed to streamline the process of loading, merging, and reflecting directory hierarchies in JSON files. With Json-Fusion, you can consolidate information scattered across different JSON files, and reflect your filesyst

Latest version **0.2.3** (published 2023-10-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install json-fusion
pnpm add json-fusion
yarn add json-fusion
bun add json-fusion
```

## Health

**Score 40/100 (D)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned.

## Facts

| | |
|---|---|
| Version | 0.2.3 |
| Published | 2023-10-01 |
| First published | 2023-08-24 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=14 |
| Dependencies | 2 |
| Unpacked size | 54.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 4 |
| Author | mew-ton |
| Maintainers | _mew_ton, hacomono-dev, maco-hacomono |
| Keywords | json, yaml, merge, hierarchies |

## Links

- npm: https://www.npmjs.com/package/json-fusion
- Repository: https://github.com/hacomono-lib/json-fusion
- Homepage: https://github.com/hacomono-lib/json-fusion#readme
- Issues: https://github.com/hacomono-lib/json-fusion/issues
- npm.io page: https://npm.io/package/json-fusion

## Dependencies (2)

- [globby](https://npm.io/package/globby.md) ^11.1.0
- [deepmerge](https://npm.io/package/deepmerge.md) ^4.3.1

## 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.2.3 (latest) — 2023-10-01
- 0.2.2 — 2023-08-24

## README

# json-fusion

![npm](https://img.shields.io/npm/v/json-fusion)
![npm package minimized gzipped size (select exports)](https://img.shields.io/bundlejs/size/json-fusion)
![GitHub](https://img.shields.io/github/license/hacomono-lib/json-fusion)
[![Release](https://github.com/hacomono-lib/json-fusion/actions/workflows/release.yml/badge.svg)](https://github.com/hacomono-lib/json-fusion/actions/workflows/release.yml)
[![Test](https://github.com/hacomono-lib/json-fusion/actions/workflows/test.yml/badge.svg)](https://github.com/hacomono-lib/json-fusion/actions/workflows/test.yml)

`json-fusion` is a Node.js library designed to streamline the process of loading, merging, and reflecting directory hierarchies in JSON files. With `json-fusion`, you can consolidate information scattered across different JSON files, and reflect your filesystem's structure directly in your data, all with just a few lines of code.

Moreover, `json-fusion` provides a special handling for `index.json` files. The contents of `index.json` files are expanded directly into the parent directory's key, rather than creating a separate index key. This allows more intuitive organization of your JSON files.

## Features

- Load all JSON files from a specified directory
- Merge multiple JSON objects into one
- Incorporate the directory hierarchy as keys in the resulting JSON object
- Special handling for `index.json` files, which are expanded directly under the parent directory's key

## Installation

```sh
npm install json-fusion
```

## Usage

Here's a basic example of how to use json-fusion:

### CommonJS

```cjs
const jsonFusion = require('json-fusion');

const path = './path/to/your/json/files';
const result = await jsonFusion(path);

console.log(result);
```

### ESModule

```mjs
import jsonFusion from 'json-fusion';

const path = './path/to/your/json/files';
const result = await jsonFusion(path);

console.log(result);
```

### Structure

Consider the following directory structure:

```plaintext
/path/to/your/json/files
├── config.json
├── users
│   ├── index.json
│   ├── john.json
│   └── jane.json
└── data
    ├── items.json
    └── purchases.json
```

Running `jsonFusion('./path/to/your/json/files')` would result in an object similar to:

```jsonc
{
  "config": {/** ./config.json */},
  "users": {
    /** index.json */
    "john": {/** ./users/john.json */},
    "jane": {/** ./users/jane.json */}
  },
  "data": {
    "items": {/** ./data/items.json */},
    "purchases": {/** ./data.purchases.json */}
  }
}
```

where `{/** */}` represents the contents of the corresponding JSON file.

## API

### `jsonFusion(path, options)`

- `path` - The path to the directory containing your JSON files.
- `options` - An optional object containing the following options:
  - `exportType` - The type of export to use. Defaults to `json`. Can be one of the following:
    - `json` - Exports the resulting object as a JSON string.
    - `yaml` - Exports the resulting object as a YAML string. required `yaml` package
    - `object` - Exports the resulting object as a JavaScript object.
  - `ignore` - An array of file names to ignore. Defaults to `['index.json']`.
  - `cwd` - The current working directory to use. Defaults to `process.cwd()`.
  - `export` - If you want to export the result to a file, you can set the path to the file to be exported.
  - `extensions` - An array of file extensions to include. Defaults to `['json']`.
    - `json` - JSON files
    - `yaml` - YAML files. required `yaml` package
  - `noSpreadIndex` - If you want to disable the special handling for `index.json` files, set this to `true`. Defaults to `false`.

## Contributing

see [CONTRIBUTING.md](./CONTRIBUTING.md)

## License

[MIT](./LICENSE)

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