Class

# JSONOptions

<div class="rst-class">

forsearch

</div>

JSO

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Contains properties to set up the Compact, DecimalPlaces, and IndentSpacing options for use with `JSONItem.ToString<jsonitem.tostring>` and `GenerateJSON</api/text/json/generatejson>`.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                       | Type                               | Read-Only | Shared |
|--------------------------------------------|------------------------------------|-----------|--------|
| `Compact<jsonoptions.compact>`             | `Boolean</api/data_types/boolean>` |           |        |
| `DecimalPlaces<jsonoptions.decimalplaces>` | `Integer</api/data_types/integer>` |           |        |
| `IndentSpacing<jsonoptions.indentspacing>` | `Integer</api/data_types/integer>` |           |        |

## Property descriptions

<div id="jsonoptions.compact">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

JSONOptions.Compact

**Compact** As `Boolean</api/data_types/boolean>`

> When getting the `String</api/data_types/string>` representation of a <span class="title-ref">JSONItem</span> using the `ToString<jsonitem.tostring>` method, setting this property to `True</api/language/true>` (the default) will remove unnecessary whitespace from the resulting string. A value of `False</api/language/false>` will result in a string with SPACEs and EndOfLines embedded to make the string more readable.
>
> This example sets Compact to `True</api/language/true>` before calling `ToString<jsonitem.tostring>`.
>
> ``` xojo
> Var person As New JSONItem
> ' This object is manipulated like a dictionary
> person.Value("Name") = "John Doe"
> person.Value("Age") = 32
> person.Value("Married") = True
> person.Value("Spouse") = "Jane Doe"
>
> Var kids As New JSONItem
> ' This object is manipulated like an array
> kids.Add("John Jr")
> kids.Add("Jamie")
> kids.Add("Jack")
> kids.Add("Josie")
> kids.AddAt(0,"Jonah")
> kids.RemoveAt(2)
> person.Value("Kids") = kids
>
> Var options As New JSONOptions
> options.Compact = True
>
> Var s As String = person.ToString(options)
> ```

<div id="jsonoptions.decimalplaces">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

JSONOptions.DecimalPlaces

**DecimalPlaces** As `Integer</api/data_types/integer>`

> Controls the amount of decimal places for numbers when you call the `ToString<jsonitem.tostring>` function.

<div id="jsonoptions.indentspacing">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

JSONOptions.IndentSpacing

**IndentSpacing** As `Integer</api/data_types/integer>`

> Controls the amount of spaces used for intending when you call the `ToString<jsonitem.tostring>` function. The default is 4.

## Sample code

In this example, a `JSONItem</api/text/json/jsonitem>` with the name “product” is created and displayed in a MessageBox. The JSON string is formatted according to the set options:

``` xojo
Var product As New JSONItem
product.Value("Name") = "Chewing gum"
product.Value("Price") = 1.50
product.Value("Weight") = 0.5725

Var options As New JSONOptions
options.Compact = True
options.DecimalPlaces = 2
options.IndentSpacing = 8

MessageBox(product.ToString(options))
```

## Compatibility

|                       |     |
|-----------------------|-----|
| **Project Types**     | All |
| **Operating Systems** | All |

<div class="seealso">

Object parent class; `JSONItem</api/text/json/jsonitem>`, `GenerateJSON</api/text/json/generatejson>`, `ParseJSON</api/text/json/parsejson>` methods; `JSONException</api/exceptions/jsonexception>`.

</div>
