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

---

# ParseJSON

This function parses **json **and fills the **destinationvariable** with appropriate values. That function is built-in in the compiler and so the syntax is slightly different. This function accepts any single dimension array or any structure as a second parameter. The first parameter has to be of type text. The destination variable declaration must confirm the **json **value type rules.  


> ℹ️ **Since firmware 20.00 **function supports parsing JSON from Text and ByteString source ( ByteString must be encoded in UTF8). Previous version supports parsing JSON from Text only.


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 can be in the range of <u>[157](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#157)</u>-<u>[179](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#179)</u><u> or  </u><u>[298](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#298)</u>. 

#### Syntax 

```visualbasic
Function ParseJSON( 
  json As Text, 
  ByRef destinationvariable As Array[1] or Structure) 
As Boolean
```

#### Syntax since firmware 20.00

```visualbasic
Function ParseJSON( 
  json As Text or ByteString, 
  ByRef destinationvariable As Array[1] or Structure) 
As Boolean
```

#### Parameters 

json 

<u>[Text](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the source json text to be parsed. 

Since firmware 20.00 command supports JSON in ByteString:

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

destinationvariable 

Structure or single dimensional array. That is the variable to be filled from the json.

The maximum size of this parameter is specified [https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510787585/CUE+System+limits#ParseJSON](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510787585/CUE+System+limits#ParseJSON). If the parameter destinationvariable is larger then the command returns False and GetLastError returns 158. 

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

# FormatJSON

This function creates **json **by the source variable. That function is built-in in the compiler and so the syntax is slightly different. This function accepts any single dimension array or any structure as the first parameter. The second parameter has to be of type text. The source variable declaration must confirm the **json **value type rules.  


> ℹ️ **Since firmware 20.00 **function supports formating JSON to Text and ByteString. Previous version supports formating JSON to Text only.


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 can be in the range of <u>[180](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#180)</u>-<u>[184](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/510525445/Command+errors#184)</u>. 

#### Syntax 

```visualbasic
Function FormatJSON( 
  sourcevariable As Array[1] or Structure 
  ByRef json As Text) 
As Boolean
```

#### Syntax since firmware 20.00

```visualbasic
Function FormatJSON( 
  sourcevariable As Array[1] or Structure 
  ByRef json As Text or ByteString) 
As Boolean
```

#### Parameters 

sourcevariable 

Structure or single dimensional array. That is the variable to fill the jsontext from. 

json 

<u>[Text](https://cue.atlassian.net/wiki/spaces/CVCHELP/pages/495058958/Data+types#Text)</u> It is the destination json text to be formatted. 

Since firmware 20.00 command supports formatting JSON to ByteString:

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

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

```visualbasic
Private Structure sPerson 
  Var tName Alias "Name" As Text [32] 
  Var tLastName Alias "Last name" As Text [32] 
  Var tNick Alias "Nick name" As Text [32] 
  Var Age As Long 
  Var Phone As Text [16] 
End Structure 

Structure PhoneBook 
  Var Owner As sPerson 
  Var aPerson Alias "Phone Book" [2] As sPerson 
End Structure 

Var MyData As PhoneBook 
Var Output As Text [4096] 

Private Process Autoexec() 
  MyData.Owner.tName := "Jack" 
  MyData.Owner.tLastName := "Black" 
  MyData.Owner.tNick := "boy" 
  MyData.Owner.Age := 30 
  MyData.Owner.Phone := "" 
  MyData.aPerson[1].tName := "John" 
  MyData.aPerson[1].tLastName := "Smith" 
  MyData.aPerson[1].tNick := "" 
  MyData.aPerson[1].Age := 12 
  MyData.aPerson[1].Phone := "+001 123 456 789" 
  MyData.aPerson[2].tName := "Mary" 
  MyData.aPerson[2].tLastName := "Lui" 
  MyData.aPerson[2].tNick := "Mam" 
  MyData.aPerson[2].Age := 25 
  MyData.aPerson[2].Phone := "+001 987 654 321" 

  If Not FormatJSON (MyData, Output) Then 
    DebugPrintFormat ("FormatJSON failed ({N})", GetLastError()) 
  Else 
    DebugPrint( Output) 
  End If 
End Process
```

It prints to the debug window: 

```visualbasic
{"Owner":{"Name":"Jack","Last name":"Black","Nick name":"boy","Age":30,"Phone":""},"Phone Book":[{"Name":"John","Last name":"Smith","Nick name":"","Age":11,"Phone":"+001 123 456 789"},{"Name":"Mary","Last name":"Lui","Nick name":"Mam","Age":25,"Phone":"+001 987 654 321"}]}
```