# magic-json-tree

> magic-json-tree Svelte component to render interactive JSON trees.

Latest version **2.0.2** (published 2023-10-01) · ISC license · 0 weekly downloads

## Install

```sh
npm install magic-json-tree
pnpm add magic-json-tree
yarn add magic-json-tree
bun add magic-json-tree
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.2 |
| Published | 2023-10-01 |
| First published | 2022-11-18 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=16.0.0 |
| Dependencies | 0 |
| Unpacked size | 56.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 74 |
| Author | Richard Laffers |
| Maintainers | rlaffers |
| Keywords | svelte, json |

## Links

- npm: https://www.npmjs.com/package/magic-json-tree
- Repository: https://github.com/rlaffers/xstate-ninja
- Homepage: https://github.com/rlaffers/xstate-ninja#readme
- Issues: https://github.com/rlaffers/xstate-ninja/issues
- npm.io page: https://npm.io/package/magic-json-tree

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

- 2.0.2 (latest) — 2023-10-01
- 2.0.1 — 2023-09-30
- 2.0.0 — 2023-09-14
- 1.1.0 — 2022-11-20
- 1.0.0 — 2022-11-18

## README

<div align="center">
  <h1>magic-json-tree</h1>
  <p>Svelte component to render interactive JSON trees.</p>
  <p>
    <a href="https://npmjs.com/package/magic-json-tree"><img src="https://img.shields.io/npm/v/magic-json-tree" alt="npm version" /></a>
    <a href="https://github.com/prettier/prettier"><img src="https://img.shields.io/badge/code_style-prettier-ff69b4.svg" alt="code style: prettier" /></a>
    <a href="http://makeapullrequest.com"><img src="https://img.shields.io/badge/PRs-welcome-brightgreen.svg" alt="PRs Welcome" /></a>
  </p>
  <hr/>
</div>

## Quick Start

```bash
npm install --save magic-json-tree
```

In your Svelte app:

```javascript
<script>
  import Tree from 'magic-json-tree'

  const json = {
    name: 'john',
    age: 123,
    male: true,
    pets: ['rat', 'flees'],
    inventory: {
      belt: ['coins', 'knife', 8, undefined],
      backpack: null,
    },
    skills: new Map([
      ['strength', 123],
      [456, ['one', 'two', 'three']],
      [['favourite', 'inputs'], { taste: 'apple', smell: 'banana' }],
    ]),
  }
</script>

<Tree value={json} />
```

This renders a tree view:

<div align="center">
  <img src="https://user-images.githubusercontent.com/489018/202722774-db620b02-25c0-45eb-a84b-999b63a5c90b.png" alt="screenshot" />
</div>

## Props

| Name          | Type                             | Default | Description                                                                                                                                                                           |
| ------------- | -------------------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `expand`      | number \| (string \| number)[]   | 0       | Pass a number to expand that many levels deep OR pass an object path like `['item', 'subItem', 'subSubItem']`                                                                         |
| `formatKey`   | ([any, any], path: any[]) => any | null    | Pass a function to format object keys. The function is passed `[key, value]` as its first parameter, and an object path as its second (e.g. `['item', 'subItem', 2, 'subSubItem']`)   |
| `formatValue` | ([any, any], path: any[]) => any | null    | Pass a function to format object values. The function is passed `[key, value]` as its first parameter, and an object path as its second (e.g. `['item', 'subItem', 2, 'subSubItem']`) |

## Example

Execute `npm run dev` and open the given URL in your browser.

## Theming

You can set some of the following CSS variables to overwrite the default colors:

```css
--mjt-color-key: var(--base1);
--mjt-color-string: var(--orange);
--mjt-color-number: var(--cyan);
--mjt-color-null: var(--yellow);
--mjt-color-undefined: var(--yellow);
--mjt-color-boolean: var(--blue);
--mjt-color-object: var(--base1);
--mjt-color-array: var(--base1);
--mjt-color-symbol: var(--green);
--mjt-color-map: var(--green);
--mjt-color-set: var(--green);
```

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