# Json — SvelteKit UI

Package: sveltekit-ui 1.1.94

Page: https://www.sveltekit-ui.com/components/json

Category: Data & content

manages json data for viewing and (optionally) editing, with features like expanding/collapsing nested objects and uploading/importing data

Public component import: `Json`

Public manager import: `create_json_manager`

## Usage

```svelte
<script>
  // Import the shared stylesheet once in your application's root layout.
  import "sveltekit-ui/style.css"
  import { Json, create_json_manager } from "sveltekit-ui"

  const manager = create_json_manager({
    label: "Project settings",
    val: { name: "Website", published: false, tags: ["svelte", "ui"] },
    is_edit_mode: true,
    is_show_buttons: true,
  })
</script>

<Json {manager} />
<pre>{JSON.stringify(manager.val, null, 2)}</pre>
```

## Configuration

### `val`

- type: any
- default: null
- description: the initial json object/array/value to display or edit

### `is_popover`

- type: boolean
- default: false
- description: if true, the json viewer/editor is placed in a popover

### `is_edit_mode`

- type: boolean
- default: false
- description: if true, displays editing controls (upload, full-edit popover, etc.)

### `is_show_buttons`

- type: boolean
- default: false
- description: if true, shows collapse, expand, copy, etc. buttons in the interface

### `label`

- type: string
- default: null
- description: optional label text to show above the json viewer

### `indentation`

- type: number
- default: 1
- description: indentation or nesting offset for the displayed structure

### `on_finish`

- type: function
- default: null
- description: called when the user taps the 'finish' button in the popover, receives the final json value

## Methods

### `set_val()`

- description: replaces the json with a new object/array/value, reprocessing into nested form
- parameters:
  - input: any
- returns: void

### `init()`

- description: initializes the manager, sets up popovers, buttons, file inputs, etc.
- parameters:
  - config: object
- returns: void

## Returned state

### `id`

- type: string
- description: unique id for this json manager instance

### `val`

- type: any
- description: the fully processed json value representing the user's final object/array or primitive

### `label`

- type: string
- description: optional label for the json viewer/editor

### `popover_manager`

- type: object
- description: manages the main popover if is_popover is true

### `popover_toggle_button_manager`

- type: object
- description: button manager to open/close the popover if is_popover is true

### `is_popover`

- type: boolean
- description: if true, the json editor is displayed in a popover

### `json_prepped`

- type: object
- description: internal nested representation of the json data structure

### `file_input_manager`

- type: object
- description: manages file input for uploading JSON or CSV

### `data_upload_popover_manager`

- type: object
- description: popover manager for the 'edit full json' text area

### `edit_json_button_manager`

- type: object
- description: button manager opening the data_upload_popover_manager

### `data_text_input_manager`

- type: object
- description: text input manager for the raw json text/csv content

### `collapse_all_button_manager`

- type: object
- description: button manager that collapses all nested objects/arrays

### `expand_all_button_manager`

- type: object
- description: button manager that expands all nested objects/arrays

### `copy_json_button_manager`

- type: object
- description: button manager that copies the final json to clipboard

### `is_show_buttons`

- type: boolean
- description: if true, shows the top row of collapse/expand/copy/etc. controls

### `is_edit_mode`

- type: boolean
- description: if true, user can directly edit nested items or the entire json

### `finish_data_upload_button_manager`

- type: object
- description: button manager that finalizes the raw text input from the data_upload_popover

### `finish_button_manager`

- type: object
- description: button manager that calls on_finish and closes the main popover
