---
name: "parseJSON"
mode: "api"
versionRequirements:
  - { name: "@ray-js/panel-sdk", version: "1.0.0" }
title: "json"
---

## parseJSON

> [VERSION] @ray-js/panel-sdk >= 1.0.0

> 💡 This function never throws; on parse failure, it silently returns the original string. Suitable for cases where the input may not be valid JSON.

### Description

Safely parse a JSON string into an object

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `str` | `string` | Yes | JSON string to parse |

### Return Value

Type: `string \| Record<string, never>`

The parsed object; if parsing fails, returns the original string; if the input is undefined, returns an empty object

### Examples

#### Basic usage

```ts
import { utils } from '@ray-js/panel-sdk';

const { parseJSON } = utils;

parseJSON('{"a":1}');  // { a: 1 }
parseJSON('not json'); // 'not json'
parseJSON(undefined);  // {}
```

---
name: "stringifyJSON"
mode: "api"
versionRequirements:
  - { name: "@ray-js/panel-sdk", version: "1.0.0" }
title: "json"
---
## stringifyJSON

> [VERSION] @ray-js/panel-sdk >= 1.0.0

> 💡 This function never throws; on serialization failure, returns the string form of the original data.

### Description

Safely serialize the given data to a JSON string

### Parameters

`Params`

| Parameter | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | `any` | Yes | Data to serialize; can be of any type |

### Return Value

None


### Examples

#### Basic usage

```ts
import { utils } from '@ray-js/panel-sdk';

const { stringifyJSON } = utils;

stringifyJSON({ a: 1 }); // '{"a":1}'
stringifyJSON('hello');  // 'hello'
stringifyJSON(null);     // ''
stringifyJSON(undefined); // ''
```
