> ## Documentation Index
> Fetch the complete documentation index at: https://docs.superoffice.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JSONBuilder

> The JSONBuilder class simplifies building JSON hierarchies. The result will be a string in correct JSON format, with string values properly escaped. This class is useful for example in combination with the HTTP class to make REST-calls.

The JSONBuilder class simplifies building JSON hierarchies. The result will be a string in correct JSON format, with string values properly escaped. This class is useful for example in combination with the HTTP class to make REST-calls.

## Constructors

### JSONBuilder()

```crmscript theme={null}
JSONBuilder
```

Initializes a new instance of the JSONBuilder class.

## Methods

## addBoolean(String,Bool)

Adds a boolean value to the current scope.

```crmscript theme={null}
Void addBoolean(String key, Bool value)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  If the current scope is an object, you must supply a key. If the current scope is an array, key must be empty.
</Note>

## addFloat(String)

Adds a float value to the current scope.

```crmscript theme={null}
Void addFloat(String key, Float value)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  If the current scope is an object, you must supply a key. If the current scope is an array, key must be empty.
</Note>

## addInteger(String,Integer)

Adds an integer value to the current scope.

```crmscript theme={null}
Void addInteger(String key, Integer value)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  If the current scope is an object, you must supply a key. If the current scope is an array, key must be empty.
</Note>

## addString(String,String)

Adds a string value to the current scope.

```crmscript theme={null}
Void addString(String key, String value)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  If the current scope is an object, you must supply a key. If the current scope is an array, key must be empty. The value does not need to be escaped, it will be escaped by JSONBuilder.
</Note>

## finalize()

Pops all levels out to the root.

```crmscript theme={null}
Void finalize()
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  You can call this function instead of multiple popLevel() if you are at then end of your structure.
</Note>

## getString()

Returns the JSON-formatted string that has been built by all push and add methods.

```crmscript theme={null}
String getString()
```

**Returns:** [CRMScript.Global.String](CRMScript.Global.String) - The JSON-formatted string.

## popLevel()

Pops a level (closes an array or an object) in the JSONBuilder.

```crmscript theme={null}
Void popLevel()
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Look at the root example for this class.
</Note>

## pushArray(String)

Adds an array to the JSONBuilder. Subsequent methods will add members inside the array.

```crmscript theme={null}
pushArray(String array)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Normally, an array will be named (because it will be a named variable in the parent scope), except for when the array is the root of the JSON structure.
</Note>

## pushObject(String)

Adds an object to the JSONBuilder. Subsequent methods will add members inside the object.

```crmscript theme={null}
Void pushObject(String object)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)

<Note>
  Normally, an object will be named (because it will be a named variable in the parent scope), except for when the object is the root of the JSON structure.
</Note>

## setPrettyPrint(Integer)

Sets whether the JSON should be pretty formatted or not.

```crmscript theme={null}
Void SetPrettyPrint(Integer indent)
```

**Returns:** [CRMScript.Global.Void](CRMScript.Global.Void)


## Related topics

- [SearchEngine](/en/automation/crmscript/reference/CRMScript.Native.SearchEngine.md)
- [Running a query](/en/automation/crmscript/searchengine/se-run.md)
- [Namespace CRMScript.Native](/en/automation/crmscript/reference/CRMScript.Native.md)
- [Array](/en/automation/crmscript/reference/CRMScript.DataStructure.Array.md)
- [Arrays](/en/automation/crmscript/fundamentals/arrays.md)
- [Struct](/en/automation/crmscript/reference/CRMScript.DataStructure.Struct.md)
