# JSON module

The JSON module can be used to transform Flow variables (records or tables) into JSON data and vice versa.

### **JSON.Decode(data)**

The generic Decode function takes a JSON record (as text) and decodes it as the specified type (T). Fields which are present in the type (T) but do not have a corresponding entry in the JSON data will be created with the default value. It is therefore recommended to specify default values for all type structures which will be decoded from JSON.

```fsharp
let data = '{"name" : "Richard", "age" : 28}';
type personType = [name = 'Not specified', age = 0, occupation = 'Unemployed'];

let myPerson = JSON.Decode<personType>(data); // Person will have occupation 'Unemployed' since the key is not present in the json data

return myPerson.age; // Returns 28
```

### **JSON.DecodeTable**

The generic DecodeTable function takes a JSON table (as text) and decodes it as a table of the specified type (T). Columns which are present in the type (T) but do not have corresponding entries in the JSON data will be created with the default value. It is therefore recommended to specify default values for all type structures which will be decoded from JSON.

```fsharp
let data = '[{"name" : "Richard", "age" : 28}, {"name" : "Samantha", "age" : 21, "occupation" : "Programmer" }]';
type personType = [name = 'Not specified', age = 0, occupation = 'Unemployed'];

let persons = JSON.DecodeTable<personType>(data);

return persons.First().name; // Will return "Richard"
```

### **JSON.Encode**

The generic Encode function takes any FlowScript record variable and encodes it as JSON.

```fsharp
let animal = [name: 'Cat', numberOfLegs: 4];

return JSON.Encode(animal); // Will return '{"name" : "Cat", "numberOfLegs" : 4.0 }'
```

### **JSON.EncodeTable**

The generic Encode function takes any FlowScript table variable and encodes it as JSON.

```fsharp
let animals = [name: 'Cat', numberOfLegs: 4] & [name: 'Millipede', numberOfLegs: 1000];

return JSON.EncodeTable(animals); // Will return '[{"name" : "Cat", "numberOfLegs" : 4.0}, {"name" : "Millipede", "numberOfLegs" : 1000.0 }]'
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.novacuraflow.com/development/flowscript/functions/json-module.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
