# fromJSON (Shared)

> Turns JSON text into a Lua value. It is the same function as `json.decode`.

- **Platform**: MY Multiplayer (MYMP)
- **Kind**: Lua Function
- **Side**: Shared
- **Category**: Data and utilities
- **URL**: https://wiki.mymp.gg/en/fromJSON

## Syntax

```lua
any fromJSON(string json)
```

## Parameters

| Name | Type | Description |
| --- | --- | --- |
| `json` | `string` | The JSON text. |

## Returns

The value read. If the text is not valid JSON, `nil` and a message saying what is wrong and where.

Objects and arrays become tables, and `null` becomes `nil` (in an array, it leaves a hole). Whole numbers become Lua integers. Over 32 levels of nesting are refused.

## Example

```lua
local data, problem = fromJSON('{"name":"Carl","money":350}')
if problem then
    outputDebugString("Bad JSON: " .. problem, 2)
else
    print(data.name, data.money)
end
```

## See also

- [toJSON (Shared)](https://wiki.mymp.gg/en/toJSON.md): Turns a Lua value into JSON text. It is the same function as json.encode.
- [json.decode (Shared)](https://wiki.mymp.gg/en/json.decode.md): Turns JSON text into a Lua value. It is the same function as fromJSON.
