JSON

A JSON variable stores structured data as a dynamic map-like object. It's perfect for storing complex, nested data structures with key-value pairs, making it ideal for API responses, configuration objects, or any hierarchical data.

When to Use

Use JSON variables when you need to:

  • Store API response data with multiple fields

  • Manage complex configuration objects

  • Store user profiles or settings

  • Handle nested or hierarchical data

  • Group related data together

  • Store objects with dynamic or unknown keys

Structure

JSON variables use key-value pairs and support nesting:

{
  "name": "John Doe",
  "age": 30,
  "email": "[email protected]",
  "address": {
    "street": "123 Main St",
    "city": "New York",
    "country": "USA"
  },
  "preferences": {
    "darkMode": true,
    "notifications": false
  },
  "tags": ["developer", "designer"]
}

Common Use Cases

1. Storing API Responses

Store structured data from API calls:

2. Configuration Objects

Store app settings or configurations:

3. User Profiles

Manage user information:

4. Form Data

Collect multiple form fields in one object:

5. Nested Data Structures

Handle complex hierarchical data:

Accessing JSON Data

Dot Notation

Access properties using dots:

Using jsonGet Function

Access properties using the jsonGet (or get) function:

Nested Properties

Access deeply nested data:

Dynamic Keys

Access properties dynamically using the jsonGet function:

Modifying JSON Data

Replacing Entire Object

Replace the whole JSON object:

You can also construct new JSON objects by modifying the response:

Working with JSON

JSON Operators

The primary JSON operator available is:

  • jsonGet() (alias: get()) - Access nested properties using path notation

See the JSON Operators documentation for detailed usage.

Accessing Nested Properties

Use jsonGet with dot notation paths:

Checking for Properties

Verify if a property exists:

JSON vs List

While both can store complex data:

JSON
List

Key-value pairs

Ordered collection of items

Access by property name

Access by index

Best for structured objects

Best for arrays of items

{"name": "John", "age": 30}

["Apple", "Banana", "Orange"]

Best Practices

  • Initialize with structure: Set an initial value with the expected structure, even if empty: {}

  • Use consistent naming: Keep property names consistent (camelCase or snake_case)

  • Validate before access: Check if properties exist before using them to avoid errors

  • Keep structure flat when possible: Deep nesting can be hard to manage; flatten when reasonable

  • Use for related data: Group related properties together in a JSON object

  • Document structure: Comment or document the expected structure of complex JSON variables

  • Handle null/undefined: Always check for missing properties in API responses

Common Patterns

Default Values

Provide fallback values for missing properties:

Conditional Access

Check before accessing nested properties:

Replacing JSON Objects

Update entire objects:

Dynamic Property Access

Use jsonGet with variable paths:

Last updated