---
title: "JSON Parser"
canonical: "https://docs.cuesystem.com/space/CVCHELP/1801257011/JSON%20Parser"
format: markdown
---
> Macro (toc)

---

 

> ℹ️ This class is supported since firmware 21.40


System Limits

Maximum number of JSON parsers used in parallel in one unit- 100

Maximum number of objects in one JSON source - 200 arrays and 4000 items 

# **_JSONParser class**

This class represents an JSON parser. It includes functions necessary for parsing JSON. 

# Parse

This function parses JSON and gets the result of parsing. The JSON must be complete before using this function. **The function does not create an internal copy of the ByteString. The ByteString must be in the same unit and must not be changed after using Parse and before using Destroy**. 

Maximum number of objects in one JSON source is 200 arrays and 4000 items. If JSON will have more items or arrays function Parse returns False.

#### Syntax 

```visualbasic
Public Function Parse(jsoninutf8 As ByteString) As Boolean
```

#### Parameters 

jsoninutf8 

<u>[ByteString](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the JSON (ByteString in UTF8 encoding) for parsing.  

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[297](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#297)</u>, <u> </u><u>[298](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#298)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

```visualbasic
Process Autoexec()   
  Var parser As _JSONParser 

  /* JSON used in example
  {
    "item1":"value1",
    "item2":"value2"
  }
  */

  If parser.Parse( &S"{\"item1\":\"value1\",\"item2\":\"value2\"}") Then 
    DebugPrint("JSON Parse OK")
  Else
    DebugPrintFormat("JSON Parse Error: {N}", GetLastError()) 
  End If 
End Process 

```

It prints to the debug window: 

```
JSON Parse OK
```

 

# GetRootItem

This function looks for the root JSON item. Before using this function, the programmer has to use the function Parse. 

#### Syntax 

```visualbasic
Public Function GetRootItem(ByRef item As _JSONItem) As Boolean
```

#### Parameters 

item

<u>_JSSONItem. </u>It is the destination instance for JSON root item.  

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

# Destroy 

This function destroys all internal JSON data of the _JSONParser instance. After using this function, the programmer must not use other functions but Parse.

> ℹ️ This function is a class destructor and the system calls it automatically when an instance of the _JSONParser class passes out of scope. Therefore, it is not necessary to call it explicitly.

#### Syntax 

```visualbasic
Public Function Destroy()
```

# **_JSONItem class**

This class has to be used for obtaining items of the JSON. _JSONItem class instance can be obtained by _JSONParse.GetRootItem or _JSONItem.GetSubItem functions

# GetName

This function fills the name of the item into the output parameter name. 

```visualbasic
Public Function GetName(ByRef name As Text) As Boolean
```

#### Parameters 

json 

<u>[Text](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the destination text for JSON item name.  

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[295](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#295)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

```visualbasic
Process Autoexec()   
  Var parser As _JSONParser 
  Var rootitem As _JSONItem 
  Var subitem As _JSONItem 
  Var itemname As Text[100] 

  /* JSON used in example
  {
    "item1":"value1",
    "item2":"value2"
  }
  */
  
  If parser.Parse( &S"{\"item1\":\"value1\",\"item2\":\"value2\"}") = False Then 
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError()) 
    Return
  End If 

  If parser.GetRootItem(rootitem) Then      
     If rootitem.GetSubItemByIndex(subitem,1) Then
        subitem.GetName(itemname)
        DebugPrint(itemname)
     End If
  End If     
End Process 

```

It prints to the debug window:

```
item1
```

# GetType

The function returns the JSON item type 

```visualbasic
Public Function GetType() As Long
```

The function returns JSONItem type. There is the enum _JSONItemTypes with all possible values.


Global Enum _JSONItemTypes

	JSONNone := 0,	

	JSONNull := 1,	

	JSONObject := 2,	

	JSONArray := 3,	

	JSONString := 4,	

	JSONNumber := 5,	

	JSONBoolean := 6	

End Enum	

```visualbasic
Process Autoexec()   
  Var parser As _JSONParser 
  Var rootitem As _JSONItem 
  Var subitem As _JSONItem 
  Var itemname As Text[100] 

  /* JSON used in example
  {
    "item1":"value1",
    "item2":"value2"
  }
  */
  
  If parser.Parse( &S"{\"item1\":\"value1\",\"item2\":\"value2\"}") = False Then 
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError()) 
    Return
  End If 

  If parser.GetRootItem(rootitem) Then 
     DebugPrint(rootitem.GetType())     
  End If     
End Process 

```

It prints to the debug window: 

```
2
```

# GetIndex

The function returns the item index in parent JSON item. JSON item has index only if  parent JSON item is of the type JSONObject or JSONArray.

```visualbasic
Public Function GetIndex(ByRef index As Long) As Boolean
```

#### Parameters 

index

<u>[Long](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long)</u> It is the destination for item index in the parent JSON item.  

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[295](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#295)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

# GetSubItemCount

This function returns the count of subitems of the item. If item has no subitem the function returns value 0. Only item of the type JSONObject or JSONArray could have any item.

```visualbasic
Public Function GetSubItemsCount() As Long
```

#### Return value 

<u>[Long](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long)</u> It is a count of subitems of the item.

```visualbasic
Process Autoexec()   
  Var parser As _JSONParser 
  Var rootitem As _JSONItem 
  Var subitem As _JSONItem 
  Var itemname As Text[100] 

  /* JSON used in example
  {
    "item1":"value1",
    "item2":"value2"
  }
  */
  
  If parser.Parse( &S"{\"item1\":\"value1\",\"item2\":\"value2\"}") = False Then 
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError()) 
    Return
  End If 

  If parser.GetRootItem(rootitem) Then 
     DebugPrint(rootitem.GetSubItemCount())     
  End If     
End Process 

```

It prints to the debug window: 

```
2
```


# GetStringValueAsText

This function gets the JSON string value of the item and sets it to the val output parameter. 

Only a JSON item of type JSONString contains text value. 

```visualbasic
Public Function GetStringValueAsText(ByRef val As Text) As Boolean
```

#### Parameters 

val

<u>[Text](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the destination for JSON item string value.  

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[294](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#294)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

```visualbasic
Process Autoexec()   
  Var parser As _JSONParser 
  Var rootitem As _JSONItem 
  Var subitem As _JSONItem 
  Var valuetext As Text[100] 

  /* JSON used in example
  {
    "item1":"value1",
    "item2":"value2"
  }
  */
  
  If parser.Parse( &S"{\"item1\":\"value1\",\"item2\":\"value2\"}") = False Then 
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError()) 
    Return
  End If 

  If parser.GetRootItem(rootitem) Then      
     If rootitem.GetSubItemByName(subitem,"item2") Then
        subitem.GetStringValueAsText(valuetext)
        DebugPrint(valuetext)
     End If
  End If     
End Process 

```

It prints to the debug window: 

```
value2
```

# GetStringValueAsByteString

This function gets the JSON string value of the item and sets it to the val output parameter. 

Only a JSON item of type JSONString contains ByteString value in UTF8. 

```visualbasic
Public Function GetStringValueAsByteString(ByRef val As ByteString) As Boolean
```

#### Parameters 

val

<u>[Text](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the destination for JSON item value.  

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[294](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#294)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

```visualbasic
Process Autoexec()   
  Var parser As _JSONParser 
  Var rootitem As _JSONItem 
  Var subitem As _JSONItem 
  Var valuebs As ByteString[100] 

  /* JSON used in example
  {
    "item1":"value1",
    "item2":"value2"
  }
  */
  
  If parser.Parse( &S"{\"item1\":\"value1\",\"item2\":\"value2\"}") = False Then 
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError()) 
    Return
  End If 

  If parser.GetRootItem(rootitem) Then      
     If rootitem.GetSubItemByName(subitem,"item2") Then
        subitem.GetStringValueAsByteString(valuebs)
        DebugPrint(valuebs)
     End If
  End If     
End Process 

```

It prints to the debug window: 

```
value2
```

# IsNumberDoubleType()

The function returns True if the JSON item is of type JSON number and the number is written as a decimal number or the number is written in exponential form or the value of the number is outside the range of the Long data type.


```visualbasic
Public Function IsNumberDoubleType() As Boolean
```

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True The if the JSON item is of type JSON number and the number is written as a decimal number or the number is written in exponential form or the value of the number is outside the range of the Long data type. Otherwise function returns False. If the JSON item is not of tyúe JSON Number the function returns False and sets error. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[295](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#295)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

# GetNumberValueAsLong

This function gets the JSON number value of the item and sets it to the val output parameter. 

Only a JSON item of type JSONNumber contains long value. 

```visualbasic
Public Function GetNumberValueAsLong(ByRef val As Long) As Boolean
```

#### Parameters 

val

<u>[Long](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long)</u> It is the destination for JSON item number value.  

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[294](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#294)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

```visualbasic
Process Autoexec()   
  Var parser As _JSONParser 
  Var rootitem As _JSONItem 
  Var subitem As _JSONItem 
  Var val As Long

  /* JSON used in example
  {
    "item1":15,
    "item2":"value2"
  }
  */
  
  If parser.Parse( &S"{\"item1\":15,\"item2\":\"value2\"}") = False Then 
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError()) 
    Return
  End If 

  If parser.GetRootItem(rootitem) Then      
     If rootitem.GetSubItemByName(subitem,"item1") Then
        subitem.GetNumberValueAsLong(val)
        DebugPrint(val)
     End If
  End If     
End Process 

```

It prints to the debug window: 

```
15
```


# GetNumberValueAsDouble

This function gets the JSON number value of the item and sets it to the val output parameter. 

Only a JSON item of type JSONNumber contains double value. 

```visualbasic
Public Function GetNumberValueAsDouble(ByRef val As Double) As Boolean
```

#### Parameters 

val

<u>[Double](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Double)</u> It is the destination for JSON item number value.  

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[294](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#294)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

```visualbasic
Process Autoexec()   
  Var parser As _JSONParser 
  Var rootitem As _JSONItem 
  Var subitem As _JSONItem 
  Var val As Double 

  /* JSON used in example
  {
    "item1":15.123456,
    "item2":"value2"
  }
  */
  
  If parser.Parse( &S"{\"item1\":15.123456,\"item2\":\"value2\"}") = False Then 
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError()) 
    Return
  End If 

  If parser.GetRootItem(rootitem) Then      
     If rootitem.GetSubItemByName(subitem,"item1") Then
        subitem.GetNumberValueAsDouble(val)
        DebugPrint(val)
     End If
  End If     
End Process 

```


It prints to the debug window: 

```
15.123456
```


# GetBooleanValue

This function gets the JSON boolean value of the item and sets it to the val output parameter. 

Only a JSON item of type JSONBoolean contains boolean value. 

```visualbasic
Public Function GetBooleanValue(ByRef val As Boolean) As Boolean
```

#### Parameters 

val

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is the destination for JSON item boolean value.  

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[294](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#294)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

```visualbasic
Process Autoexec()   
  Var parser As _JSONParser 
  Var rootitem As _JSONItem 
  Var subitem As _JSONItem 
  Var val As Boolean

  /* JSON used in example
  {
    "item1":true,
    "item2":"value2"
  }
  */
  
  If parser.Parse( &S"{\"item1\":true,\"item2\":\"value2\"}") = False Then 
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError()) 
    Return
  End If 

  If parser.GetRootItem(rootitem) Then      
     If rootitem.GetSubItemByName(subitem,"item1") Then
        subitem.GetBooleanValue(val)
        DebugPrint(val)
     End If
  End If     
End Process 

```

It prints to the debug window: 

```
True
```

# GetJSON

This function gets the JSON item as JSON (ByteString in UTF8) and sets it to the jsoninutf8 output parameter. Only a JSON item of type JSONObject or JSONArray contains JSON. 

```visualbasic
Public Function GetJSON(ByRef jsoninutf8 As ByteString) As Boolean
```

#### Parameters 

jsoninutf8

<u>[ByteString](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is the destination for JSON item string value.  

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[294](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#294)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

```visualbasic
Process Autoexec()  
  Var parser As _JSONParser
  Var rootitem As _JSONItem
  Var subitem As _JSONItem
  Var subitemjson As ByteString[200]

  /* JSON used in example
  {
    "item1":true,
    "item2":
      {
        "n1":11,
        "n2":55
      }
  }
  */
  
  If parser.Parse( &S"{\"item1\":true,\"item2\":{\"n1\":11,\"n2\":55}}") = False Then
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError())
    Return
  End If

  If parser.GetRootItem(rootitem) Then 
     If rootitem.GetSubItemByName(subitem,"item2") Then
        subitem.GetJSON(subitemjson)
        DebugPrint(subitemjson)
     End If
  End If    
End Process

```

It prints to the debug window: 

```
{"n1":11,"n2":55}
```


# GetSubItemByIndex

This function gets a JSON subitem by index and sets it to the parameter item. First subitem has index  1. Only JSON items with type JSONArray or JSONObject have subitems.

```visualbasic
Public Function GetSubItemByIndex(ByRef item As _JSONItem, index As Long) As Boolean
```

#### Parameters 

item

<u>[ByteString](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is the destination for JSON item. 

index

 <u>[Long](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long)</u> It is a index of the JSON item 

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

```visualbasic
Process Autoexec()   
  Var parser As _JSONParser 
  Var rootitem As _JSONItem 
  Var subitem As _JSONItem 
  Var itemname As Text[100] 

  /* JSON used in example
  {
    "item1":"value1",
    "item2":"value2"
  }
  */
  
  If parser.Parse( &S"{\"item1\":\"value1\",\"item2\":\"value2\"}") = False Then 
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError()) 
    Return
  End If 

  If parser.GetRootItem(rootitem) Then      
     If rootitem.GetSubItemByIndex(subitem,1) Then
        subitem.GetName(itemname)
        DebugPrint(itemname)
     End If
  End If     
End Process 

```

It prints to the debug window: 

```
value1
```


# GetSubItemByName

This function gets a JSON subitem by name and sets it to the parameter item. Only JSON items with type JSONObject have subitems with names.

```visualbasic
Public Function GetSubItemByName(ByRef item As _JSONItem, name As Text, Optional caseinsensitive As Boolean := False) As Boolean
```

#### Parameters 

item

<u>[ByteString](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is the destination for JSON item. 

name

 <u>[Long](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Long)</u> It is a index of the JSON item Return value 

caseinsensitive

 <u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is a way how to compare item name.  If it is False the case sensitive comparation is used otherwise case insensitive comparation is used.

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

```visualbasic
Process Autoexec()   
  Var parser As _JSONParser 
  Var rootitem As _JSONItem 
  Var subitem As _JSONItem 
  Var val As Boolean 

  /* JSON used in example
  {
    "item1":true,
    "item2":"value2"
  }
  */
  
  If parser.Parse( &S"{\"item1\":true,\"item2\":\"value2\"}") = False Then 
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError()) 
    Return
  End If 

  If parser.GetRootItem(rootitem) Then      
     If rootitem.GetSubItemByName(subitem,"item1") Then
        subitem.GetBooleanValue(val)
        DebugPrint(val)
     End If
  End If     
End Process 

```

It prints to the debug window: 

```
True
```


# GetSubItemByPath

This function gets a JSON subitem by names or/and indexes and sets it to the parameter item. Only JSON items with type JSONObject have subitems with names. First subitem has index  1. The **case sensitive comparation is used for names.**

```visualbasic
Public Function GetSubItemByPath(ByRef item As _JSONItem, ParamArray) As Boolean
```

#### Parameters 

item

<u>[ByteString](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is the destination for JSON item string value.  

ParamArray

     <u>[Long](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u><u>,</u><u>[Text](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a path of names/indexes of the subitem Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[296](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#296)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

```visualbasic
Process Autoexec()  
  Var parser As _JSONParser
  Var rootitem As _JSONItem
  Var subitem As _JSONItem
  Var val As Long

  /* JSON used in example
  {
    "item1":true,
    "item2":
      {
        "n1":11,
        "n2":22,
        "ARRAY":
          [
            33,
            44,
            55
          ]
      }
  }
  */
  
  If parser.Parse( &S"{\"item1\":true,\"item2\":{\"n1\":11,\"n2\":22,\"ARRAY\":[33,44,55]}}") = False Then
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError())
    Return
  End If

  If parser.GetRootItem(rootitem) Then 
     If rootitem.GetSubItemByPath(subitem,"item2","ARRAY",2) Then
        DebugPrintFormat("Item type: {n}", subitem.GetType())
        subitem.GetNumberValueAsLong(val)
        DebugPrintFormat("Item value: {n}", val)        
     End If
  End If    
End Process

```

It prints to the debug window: 

```
Item type: 5
Item value: 44
```

# GetSubItemByPathCaseInsensitive

This function gets a JSON subitem by names or/and indexes and sets it to the parameter item. Only JSON items with type JSONObject have subitems with names. First subitem has index  1. The **case insensitive comparation is used for names.**

```visualbasic
Public Function GetSubItemByPathCaseInsensitive(ByRef item As _JSONItem, ParamArray) As Boolean
```

#### Parameters 

item

<u>[ByteString](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is the destination for JSON item string value.  

ParamArray

     <u>[Long](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u><u>,</u><u>[Text](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#ByteString)</u> It is a path of names/indexes of the subitem 

#### Return value 

<u>[Boolean](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Boolean)</u> It is True on success or False if an error occurs. The function GetLastError returns the error number. 

The function <u>[GetLastError](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#GetLastError)</u> returns the error number that occurred while executing the command. The errors that can happen: <u>[293](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#293)</u>, <u>[296](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#296)</u>, <u>[2147483645](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#2147483645)</u>. 

```visualbasic
Process Autoexec()  
  Var parser As _JSONParser
  Var rootitem As _JSONItem
  Var subitem As _JSONItem
  Var val As Long

  /* JSON used in example
  {
    "item1":true,
    "item2":
      {
        "n1":11,
        "n2":22,
        "ARRAY":
          [
            33,
            44,
            55
          ]
      }
  }
  */
  
  If parser.Parse( &S"{\"item1\":true,\"item2\":{\"n1\":11,\"n2\":22,\"ARRAY\":[33,44,55]}}") = False Then
    DebugPrintFormat( "JSON Parse Error: {N}", GetLastError())
    Return
  End If

  If parser.GetRootItem(rootitem) Then 
     If rootitem.GetSubItemByPathCaseInsensitive(subitem,"item2","array",3) Then
        DebugPrintFormat("Item type: {n}", subitem.GetType())
        subitem.GetNumberValueAsLong(val)
        DebugPrintFormat("Item value: {n}", val)
     End If
  End If    
End Process

```

It prints to the debug window: 

```
Item type: 5
Item value: 55
```