Class

# JSONItem

<div class="rst-class">

forsearch

</div>

JSONItem

<div class="rst-class">

forsearch

</div>

JSON

<div class="rst-class">

forsearch

</div>

JSO

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

## Description

Used for parsing and creating Javascript Object Notation (JSON) strings. A <span class="title-ref">JSONItem</span> can use either named keys or indexed values (like an array), but not both. See the Notes section for more information.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                                    | Type                               | Read-Only | Shared |
|-----------------------------------------|------------------------------------|-----------|--------|
| `IndentSpacing<jsonitem.indentspacing>` | `Integer</api/data_types/integer>` |           |        |
| `ToString<jsonitem.tostring>`           | `String</api/data_types/string>`   |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                  | Parameters                                                                                                                | Returns                            | Shared |
|---------------------------------------|---------------------------------------------------------------------------------------------------------------------------|------------------------------------|--------|
| `Add<jsonitem.add>`                   | value As `Variant</api/data_types/variant>`                                                                               |                                    |        |
| `AddAt<jsonitem.addat>`               | index As `Integer</api/data_types/integer>`, value As `Variant</api/data_types/variant>`                                  |                                    |        |
| `Child<jsonitem.child>`               | key As `String</api/data_types/string>`                                                                                   | JSONItem                           |        |
|                                       | key As `String</api/data_types/string>`, `Assigns</api/language/assigns>` value As JSONItem                               |                                    |        |
| `ChildAt<jsonitem.childat>`           | index As `Integer</api/data_types/integer>`                                                                               | JSONItem                           |        |
|                                       | index As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As JSONItem                           |                                    |        |
| `Constructor<jsonitem.constructor0>`  |                                                                                                                           |                                    |        |
| `Constructor<jsonitem.constructor1>`  | JSONString As `String</api/data_types/string>`                                                                            |                                    |        |
| `Constructor<jsonitem.constructor2>`  | d As `Dictionary</api/language/dictionary>`                                                                               |                                    |        |
| `Count<jsonitem.count>`               |                                                                                                                           | `Integer</api/data_types/integer>` |        |
| `HasKey<jsonitem.haskey>`             | key As `String</api/data_types/string>`                                                                                   | `Boolean</api/data_types/boolean>` |        |
| `IsArray<jsonitem.isarray>`           |                                                                                                                           | `Boolean</api/data_types/boolean>` |        |
| `KeyAt<jsonitem.keyat>`               | Index As `Integer</api/data_types/integer>`                                                                               | `String</api/data_types/string>`   |        |
| `Keys<jsonitem.keys>`                 |                                                                                                                           | `String()</api/data_types/string>` |        |
| `LastRowIndex<jsonitem.lastrowindex>` |                                                                                                                           | `Integer</api/data_types/integer>` |        |
| `Load<jsonitem.load>`                 | JSONString As `String</api/data_types/string>`                                                                            |                                    |        |
| `Lookup<jsonitem.lookup>`             | key As `String</api/data_types/string>`, DefaultValue As `Variant</api/data_types/variant>`                               | `Variant</api/data_types/variant>` |        |
| `Remove<jsonitem.remove>`             | key As `String</api/data_types/string>`                                                                                   |                                    |        |
| `RemoveAll<jsonitem.removeall>`       |                                                                                                                           |                                    |        |
| `RemoveAt<jsonitem.removeat>`         | Index As `Integer</api/data_types/integer>`                                                                               |                                    |        |
| `ToString<jsonitem.tostring2>`        | options As `JSONOptions</api/text/json/jsonoptions>`                                                                      | `String</api/data_types/string>`   |        |
| `Value<jsonitem.value>`               | key As `String</api/data_types/string>`                                                                                   | `Variant</api/data_types/variant>` |        |
|                                       | key As `String</api/data_types/string>`, `Assigns</api/language/assigns>` value As `Variant</api/data_types/variant>`     |                                    |        |
| `ValueAt<jsonitem.valueat>`           | index As `Integer</api/data_types/integer>`                                                                               | `Variant</api/data_types/variant>` |        |
|                                       | index As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Variant</api/data_types/variant>` |                                    |        |

## Property descriptions

<div id="jsonitem.indentspacing">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.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 3.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> The property is supported for Android only.
>
> </div>

<div id="jsonitem.tostring">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.ToString

**ToString** As `String</api/data_types/string>`

> Returns a JSON String representing the current object.

## Method descriptions

<div id="jsonitem.add">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.Add

**Add**(value As `Variant</api/data_types/variant>`)

> Adds the passed *value* to the end of a <span class="title-ref">JSONItem</span> array.

<div id="jsonitem.addat">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.AddAt

**AddAt**(index As `Integer</api/data_types/integer>`, value As `Variant</api/data_types/variant>`)

> Adds the passed *value* into a <span class="title-ref">JSONItem</span> array at the position specified by *index*.

<div id="jsonitem.child">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.Child

**Child**(key As `String</api/data_types/string>`) As JSONItem

> Returns the <span class="title-ref">JSONItem</span> matching the *key* passed.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> Keys in JSON are case-sensitive.
>
> </div>

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

**Child**(key As `String</api/data_types/string>`, `Assigns</api/language/assigns>` value As <span class="title-ref">JSONItem</span>)

> Sets the <span class="title-ref">JSONItem</span> matching the *key* passed to the *value* passed.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> Keys in JSON are case-sensitive.
>
> </div>

<div id="jsonitem.childat">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.ChildAt

**ChildAt**(index As `Integer</api/data_types/integer>`) As <span class="title-ref">JSONItem</span>

> Returns the <span class="title-ref">JSONItem</span> at the *index* passed.

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

**ChildAt**(index As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As <span class="title-ref">JSONItem</span>)

> Assigns <span class="title-ref">JSONItem</span> *value* to the <span class="title-ref">JSONItem</span> at the *index* passed.
>
> ``` xojo
> Var myChild As New JSONItem
> myChildren.ChildAt(2) = myChild
> ```

<div id="jsonitem.constructor0">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.Constructor

**Constructor**

> <div class="note">
>
> <div class="title">
>
> Note
>
> </div>
>
> `Constructors</api/language/constructor>` are special methods called when you create an object with the `New</api/language/new>` keyword and pass in the parameters above.
>
> </div>
>
> Creates an empty JSON object.

<div id="jsonitem.constructor1">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.Constructor

**Constructor**(JSONString As `String</api/data_types/string>`)

> Parses the passed JSON string into the document. If any parsing errors occur, a `JSONException</api/exceptions/jsonexception>` will be thrown.
>
> ``` xojo
> Var js As String = "{""Name"":""John Doe"",""Age"":32,""Kids"":[""Jonah"",""John Jr""],""Married"":true,""Spouse"":""Jane Doe""}"
> Var j As New JSONItem(js)
> ```

<div id="jsonitem.constructor2">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.Constructor

**Constructor**(d As `Dictionary</api/language/dictionary>`)

> Parses the passed Dictionary string into the document. If any parsing errors occur, a `JSONException</api/exceptions/jsonexception>` will be thrown.

<div id="jsonitem.count">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.Count

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

> Returns the number of children.
>
> ``` xojo
> Var person As New JSONItem
> Var i As Integer
>
> //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"
>
> i = person.Count
> ```

<div id="jsonitem.haskey">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.HasKey

**HasKey**(key As `String</api/data_types/string>`) As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` if the child *key* exists.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> Keys in JSON are case-sensitive.
>
> </div>
>
> The following example calls HasKey to check if the passed key exists.
>
> ``` xojo
> If myUncle.HasKey("Name") Then
> MessageBox("myUncle.Name has a name.")
> End If
> ```

<div id="jsonitem.isarray">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.IsArray

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

> Returns `True</api/language/true>` if the <span class="title-ref">JSONItem</span> is being treated as an array and `False</api/language/false>` if it acts as a `Dictionary</api/language/dictionary>`.

<div id="jsonitem.keyat">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.KeyAt

**KeyAt**(Index As `Integer</api/data_types/integer>`) As `String</api/data_types/string>`

> Returns the name of a child key by *Index*. Array items will return an empty string.
>
> ``` 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 s2 As String
> s2 = person.KeyAt(1) ' returns "Age"
> ```

<div id="jsonitem.keys">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.Keys

**Keys** As `String()</api/data_types/string>`

> Returns the keys of the children. Array items will not be included.
>
> This example populates a `String</api/data_types/string>` array with the keys of the person <span class="title-ref">JSONItem</span>.
>
> ``` 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 people() As String
> people() = person.Keys ' the array will now contain the keys as used above
> ```

<div id="jsonitem.lastrowindex">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.LastRowIndex

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

> The number of the last row of the <span class="title-ref">JSONItem</span>.

<div id="jsonitem.load">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.Load

**Load**(JSONString As `String</api/data_types/string>`)

> Loads and parses a JSON `String</api/data_types/string>`. If any parsing errors occur, a `JSONException</api/exceptions/jsonexception>` will be thrown.
>
> This example loads a JSON string, s, into a <span class="title-ref">JSONItem</span>.
>
> ``` xojo
> Var r As New JSONItem
> r.Load(s)
> ```

<div id="jsonitem.lookup">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.Lookup

**Lookup**(key As `String</api/data_types/string>`, defaultValue As `Variant</api/data_types/variant>`) As `Variant</api/data_types/variant>`

> Looks up the passed value of *key*. Returns a `Variant</api/data_types/variant>`.
>
> If *key* is found, it returns the corresponding value. If *key* is not found, it returns the passed *defaultValue*.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> Keys in JSON are case-sensitive.
>
> </div>
>
> ``` xojo
> Var myChild As New JSONItem
>
> myChild.Value("Name") = "Fred"
> myChild.value("Age") = 12
> myChild.value("Married") = False
>
> Var v As Variant
> v = myChild.Lookup("Age", "Data not found")
> MessageBox(v) ' displays the value for Age
> ```

<div id="jsonitem.remove">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.Remove

**Remove**(key As `String</api/data_types/string>`)

> Removes the child with the passed *key*.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> Keys in JSON are case-sensitive.
>
> </div>
>
> This example removes a value using its key:
>
> ``` 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"
> person.Remove("Age")
> ```

<div id="jsonitem.removeall">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.RemoveAll

**RemoveAll**

> Removes all children and resets the <span class="title-ref">JSONItem</span> type (object or array).
>
> ``` xojo
> Var person As New JSONItem
> .
> .
> person.RemoveAll
> ```

<div id="jsonitem.removeat">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.RemoveAt

**RemoveAt**(Index As `Integer</api/data_types/integer>`)

> Removes the child with the passed *Index*.
>
> This example removes a value using its index:
>
> ``` xojo
> 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
> ```

<div id="jsonitem.tostring2">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.ToString

**ToString**(options As `JSONOptions</api/text/json/jsonoptions>`) As `String</api/data_types/string>`

> Returns a JSON String representing the current object which the *options* passed.
>
> 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))
> ```

<div id="jsonitem.value">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.Value

**Value**(key As `String</api/data_types/string>`) As `Variant</api/data_types/variant>`

> Returns the value associated with the *key* passed.
>
> Values can be of any of the following types: `Boolean</api/data_types/boolean>`, Number, <span class="title-ref">JSONItem</span>, `String</api/data_types/string>`, Array (containing Strings, Numbers, Booleans, or JSONItems), or `Nil</api/language/nil>`.

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

**Value**(key As `String</api/data_types/string>`, `Assigns</api/language/assigns>` value As `Variant</api/data_types/variant>`)

> Sets the *value* passed to the *key* passed.
>
> Values can be of any of the following types: `Boolean</api/data_types/boolean>`, Number, <span class="title-ref">JSONItem</span>, `String</api/data_types/string>`, Array (containing Strings, Numbers, Booleans, or JSONItems), or `Nil</api/language/nil>`.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> Keys in JSON are case-sensitive.
>
> </div>

<div id="jsonitem.valueat">

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

</div>

<div class="rst-class">

forsearch

</div>

JSONItem.ValueAt

**ValueAt**(index As `Integer</api/data_types/integer>`) As `Variant</api/data_types/variant>`

> Returns a named child's value by *index*.

**ValueAt**(index As `Integer</api/data_types/integer>`, `Assigns</api/language/assigns>` value As `Variant</api/data_types/variant>`)

> Sets a named child's *value* by *index*.

## Notes

JSON is a lightweight data exchange format. It is described at [here](http://json.org). It is based on the Javascript language and uses two structures.

JSON Objects can contain named data a collection of *name-value* pairs (like a `Dictionary</api/language/dictionary>`) as well as indexed data (like an array). To facilitate this, JSONItems can manipulate data in either way with the following restrictions:

- The first element that you add to a <span class="title-ref">JSONItem</span> determines its type.
- Array objects can be accessed only by index.
- A <span class="title-ref">JSONItem</span>'s type cannot be changed without resetting the object with the Clear method.

Names must be `Strings</api/data_types/string>`, must be unique within an object and are case-sensitive.

Values can be any of the following types: `Strings</api/data_types/string>`, numbers, JSONItems, arrays (string, number or boolean), `Booleans</api/data_types/boolean>`, or `Nil</api/language/nil>`.

Per the JSON spec, strings must be UTF8-encoded. Unless you are specifically encoding them differently, they will be UTF8 by default.

## Sample code

This code populates a <span class="title-ref">JSONItem</span> with data and then displays it in its raw form in a TextArea:

``` 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

Person.Compact = True
Var s As String = person.ToString

TextArea1.Text = s 
```

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

Create a JSONItem from a JSON String:

``` xojo
Var js As String = "{""Name"":""John Doe"",""Age"":32,""Kids"":[""Jonah"",""John Jr""],""Married"":true,""Spouse"":""Jane Doe""}"
Var j As New JSONItem(js)
```

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

Convert a Dictionary into a JSONItem:

``` xojo
Var d As New Dictionary
d.Value("Name") = "John Doe"
d.Value("Age") = 32
d.Value("Married") = True
d.Value("Spouse") = "Jane Doe"

Var j As JSONItem
j = d
```

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

Create a JSONItem with code and convert to a JSON String:

``` 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.AddAt(0, "Jonah")
kids.RemoveAt(2)

' Add the Kids object to the Person object
person.Value("Kids") = kids

' Convert to a JSON String
Var s As String = person.ToString
```

## Compatibility

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

<div class="seealso">

Object parent class; `JSONOptions</api/text/json/jsonoptions>`, `Dictionary</api/language/dictionary>` class; `GenerateJSON</api/text/json/generatejson>`, `ParseJSON</api/text/json/parsejson>` methods; `JSONException</api/exceptions/jsonexception>`.

</div>
