# JSON

## Overview

The JSON object contains static methods for parsing values from and converting values to JSON.

For more information see: [JSON (MDN)](https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/JSON).

## Methods Summarized

| Type                                                                         | Name                                                                 | Summary                                                                                                                                                                           |
| ---------------------------------------------------------------------------- | -------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) | [parse(text)](#parse-text)                                           | Parses a string as JSON and returns the parsed value.                                                                                                                             |
| [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) | [parse(text, reviver)](#parse-text-reviver)                          | Parses a string as JSON and returns the parsed value.                                                                                                                             |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) | [stringify(value)](#stringify-value)                                 | Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified  |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) | [stringify(value, replacer)](#stringify-value-replacer)              | Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified. |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) | [stringify(value, replacer, space)](#stringify-value-replacer-space) | Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified. |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) | [stringify(value, replacer, space)](#stringify-value-replacer-space) | Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified. |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) | [stringify(value, replacer)](#stringify-value-replacer)              | Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified. |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) | [stringify(value, replacer, space)](#stringify-value-replacer-space) | Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified. |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) | [stringify(value, replacer, space)](#stringify-value-replacer-space) | Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified. |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) | [stringify(value, replacer)](#stringify-value-replacer)              | Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified. |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) | [stringify(value, replacer, space)](#stringify-value-replacer-space) | Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified. |
| [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) | [stringify(value, replacer, space)](#stringify-value-replacer-space) | Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified. |

## Methods Detailed

### parse(text)

Parses a string as JSON and returns the parsed value.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** The string to parse as JSON. See the JSON object for a description of JSON syntax.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)

**Sample**

```js
JSON.parse('[1, 5, "false"]');
```

### parse(text, reviver)

Parses a string as JSON and returns the parsed value.

**Parameters**

* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **text** The string to parse as JSON. See the JSON object for a description of JSON syntax.
* [Function](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/function) **reviver** A function, prescribes how the value originally produced by parsing is transformed, before being returned.

**Returns:** [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object)

**Sample**

```js
var transformed = JSON.parse('{"p": 5}', function(k, v) { if (k === "") return v; return v * 2; });
```

### stringify(value)

Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value** The value to convert to a JSON string.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)

**Sample**

```js
JSON.stringify([1, "false", false])
```

### stringify(value, replacer)

Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.\
As a function, the replacer takes two parameters, the key and the value being stringified. Initially it gets called with an empty key representing the object being stringified,\
and it then gets called for each property on the object or array being stringified.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value** The value to convert to a JSON string.
* [Function](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/function) **replacer** If a function, transforms values and properties encountered while stringifying; if an array (of String or Number), specifies the set of properties included in objects in the final string.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)

**Sample**

```js
function censor(key, value) {
 if (typeof(value) == "string") {
   return undefined;
 }
 return value;
}

var foo = {foundation: "Mozilla", model: "box", week: 45, transport: "car", month: 7};
var jsonString = JSON.stringify(foo, censor);
```

### stringify(value, replacer, space)

Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.\
As a function, the replacer takes two parameters, the key and the value being stringified. Initially it gets called with an empty key representing the object being stringified,\
and it then gets called for each property on the object or array being stringified.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value** The value to convert to a JSON string.
* [Function](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/function) **replacer** If a function, transforms values and properties encountered while stringifying; if an array (of String or Number), specifies the set of properties included in objects in the final string.
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **space** The space argument may be used to control spacing in the final string (causes the resulting string to be pretty-printed). If it is a number, successive levels in the stringification will each be indented by this many space characters (up to 10). If it is a string, successive levels will indented by this string (or the first ten characters of it).

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)

**Sample**

```js
JSON.stringify({ uno: 1, dos : 2 }, null, '\t')
```

### stringify(value, replacer, space)

Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.\
As a function, the replacer takes two parameters, the key and the value being stringified. Initially it gets called with an empty key representing the object being stringified,\
and it then gets called for each property on the object or array being stringified.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value** The value to convert to a JSON string.
* [Function](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/function) **replacer** If a function, transforms values and properties encountered while stringifying; if an array (of String or Number), specifies the set of properties included in objects in the final string.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **space** The space argument may be used to control spacing in the final string (causes the resulting string to be pretty-printed). If it is a number, successive levels in the stringification will each be indented by this many space characters (up to 10). If it is a string, successive levels will indented by this string (or the first ten characters of it).

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)

**Sample**

```js
JSON.stringify({ uno: 1, dos : 2 }, null, '\t')
```

### stringify(value, replacer)

Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.\
As a function, the replacer takes two parameters, the key and the value being stringified. Initially it gets called with an empty key representing the object being stringified,\
and it then gets called for each property on the object or array being stringified.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value** The value to convert to a JSON string.
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **replacer** If a function, transforms values and properties encountered while stringifying; if an array (of String or Number), specifies the set of properties included in objects in the final string.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)

**Sample**

```js
function censor(key, value) {
 if (typeof(value) == "string") {
   return undefined;
 }
 return value;
}

var foo = {foundation: "Mozilla", model: "box", week: 45, transport: "car", month: 7};
var jsonString = JSON.stringify(foo, censor);
```

### stringify(value, replacer, space)

Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.\
As a function, the replacer takes two parameters, the key and the value being stringified. Initially it gets called with an empty key representing the object being stringified,\
and it then gets called for each property on the object or array being stringified.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value** The value to convert to a JSON string.
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **replacer** If a function, transforms values and properties encountered while stringifying; if an array (of String or Number), specifies the set of properties included in objects in the final string.
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **space** The space argument may be used to control spacing in the final string (causes the resulting string to be pretty-printed). If it is a number, successive levels in the stringification will each be indented by this many space characters (up to 10). If it is a string, successive levels will indented by this string (or the first ten characters of it).

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)

**Sample**

```js
JSON.stringify({ uno: 1, dos : 2 }, null, '\t')
```

### stringify(value, replacer, space)

Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.\
As a function, the replacer takes two parameters, the key and the value being stringified. Initially it gets called with an empty key representing the object being stringified,\
and it then gets called for each property on the object or array being stringified.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value** The value to convert to a JSON string.
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **replacer** If a function, transforms values and properties encountered while stringifying; if an array (of String or Number), specifies the set of properties included in objects in the final string.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **space** The space argument may be used to control spacing in the final string (causes the resulting string to be pretty-printed). If it is a number, successive levels in the stringification will each be indented by this many space characters (up to 10). If it is a string, successive levels will indented by this string (or the first ten characters of it).

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)

**Sample**

```js
JSON.stringify({ uno: 1, dos : 2 }, null, '\t')
```

### stringify(value, replacer)

Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.\
As a function, the replacer takes two parameters, the key and the value being stringified. Initially it gets called with an empty key representing the object being stringified,\
and it then gets called for each property on the object or array being stringified.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value** The value to convert to a JSON string.
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **replacer** If a function, transforms values and properties encountered while stringifying; if an array (of String or Number), specifies the set of properties included in objects in the final string.

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)

**Sample**

```js
function censor(key, value) {
 if (typeof(value) == "string") {
   return undefined;
 }
 return value;
}

var foo = {foundation: "Mozilla", model: "box", week: 45, transport: "car", month: 7};
var jsonString = JSON.stringify(foo, censor);
```

### stringify(value, replacer, space)

Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.\
As a function, the replacer takes two parameters, the key and the value being stringified. Initially it gets called with an empty key representing the object being stringified,\
and it then gets called for each property on the object or array being stringified.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value** The value to convert to a JSON string.
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **replacer** If a function, transforms values and properties encountered while stringifying; if an array (of String or Number), specifies the set of properties included in objects in the final string.
* [Number](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/number) **space** The space argument may be used to control spacing in the final string (causes the resulting string to be pretty-printed). If it is a number, successive levels in the stringification will each be indented by this many space characters (up to 10). If it is a string, successive levels will indented by this string (or the first ten characters of it).

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)

**Sample**

```js
JSON.stringify({ uno: 1, dos : 2 }, null, '\t')
```

### stringify(value, replacer, space)

Convert a value to JSON, optionally replacing values if a replacer function is specified, or optionally including only the specified properties if a replacer array is specified.\
As a function, the replacer takes two parameters, the key and the value being stringified. Initially it gets called with an empty key representing the object being stringified,\
and it then gets called for each property on the object or array being stringified.

**Parameters**

* [Object](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/object) **value** The value to convert to a JSON string.
* [Array](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/array) **replacer** If a function, transforms values and properties encountered while stringifying; if an array (of String or Number), specifies the set of properties included in objects in the final string.
* [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string) **space** The space argument may be used to control spacing in the final string (causes the resulting string to be pretty-printed). If it is a number, successive levels in the stringification will each be indented by this many space characters (up to 10). If it is a string, successive levels will indented by this string (or the first ten characters of it).

**Returns:** [String](https://docs.servoy.com/reference/servoycore/dev-api/js-lib/string)

**Sample**

```js
JSON.stringify({ uno: 1, dos : 2 }, null, '\t')
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.servoy.com/reference/servoycore/dev-api/js-lib/json.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
