> ## Documentation Index
> Fetch the complete documentation index at: https://docs.spojit.com/llms.txt
> Use this file to discover all available pages before exploring further.

# JSON Tools

> Parse, query, transform, and manipulate JSON data.

The JSON Tools connector provides operations for parsing, querying with JSONPath, and transforming JSON data within your workflows.

<Note>No connection required; this utility connector works out of the box.</Note>

## Tools

<AccordionGroup>
  <Accordion title="parse: Parse a JSON string">
    Parse a JSON string into a structured object.

    <ParamField body="json" type="string" required>
      JSON string to parse.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "json": "{\"name\":\"Alice\",\"age\":30,\"active\":true}"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "name": "Alice",
      "age": 30,
      "active": true
    }
    ```
  </Accordion>

  <Accordion title="stringify: Convert to JSON string">
    Serialize data to a JSON string.

    <ParamField body="data" type="any" required>
      Data to serialize.
    </ParamField>

    <ParamField body="pretty" type="boolean" default="true">
      Pretty-print with indentation.
    </ParamField>

    <ParamField body="indent" type="number" default="2">
      Number of indentation spaces.
    </ParamField>

    <ParamField body="encoding" type="enum" default="utf8">
      Output encoding for the `result` field: `utf8` (default) or `base64` (for email attachments, SFTP uploads, or knowledge-base embedding). The response includes an `encoding` tag.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "data": { "name": "Alice", "roles": ["admin", "user"] },
      "pretty": false
    }
    ```

    **Example response:**

    ```json theme={null}
    "{\"name\":\"Alice\",\"roles\":[\"admin\",\"user\"]}"
    ```
  </Accordion>

  <Accordion title="query: Query with JSONPath">
    Extract data using JSONPath expressions.

    <ParamField body="data" type="any" required>
      JSON data to query.
    </ParamField>

    <ParamField body="path" type="string" required>
      JSONPath expression (e.g., `$.store.book[*].author`).
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "data": {
        "store": {
          "books": [
            { "title": "Dune", "price": 12.99 },
            { "title": "Neuromancer", "price": 9.99 },
            { "title": "Foundation", "price": 14.99 }
          ]
        }
      },
      "path": "$.store.books[?(@.price<13)]"
    }
    ```

    **Example response:**

    ```json theme={null}
    [
      { "title": "Dune", "price": 12.99 },
      { "title": "Neuromancer", "price": 9.99 }
    ]
    ```
  </Accordion>

  <Accordion title="flatten: Flatten nested JSON">
    Convert nested objects to flat dot-notation keys.

    <ParamField body="data" type="any" required>
      JSON data to flatten.
    </ParamField>

    <ParamField body="delimiter" type="string" default=".">
      Key separator.
    </ParamField>

    <ParamField body="safe" type="boolean" default="false">
      Preserve arrays instead of flattening them.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "data": {
        "user": {
          "name": "Alice",
          "address": { "city": "Portland", "zip": "97201" }
        }
      }
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "user.name": "Alice",
      "user.address.city": "Portland",
      "user.address.zip": "97201"
    }
    ```
  </Accordion>

  <Accordion title="unflatten: Unflatten dot notation">
    Convert flat dot-notation keys back to nested objects.

    <ParamField body="data" type="any" required>
      Flattened data.
    </ParamField>

    <ParamField body="delimiter" type="string" default=".">
      Key separator.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "data": {
        "user.name": "Alice",
        "user.address.city": "Portland",
        "user.address.zip": "97201"
      }
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "user": {
        "name": "Alice",
        "address": { "city": "Portland", "zip": "97201" }
      }
    }
    ```
  </Accordion>

  <Accordion title="merge: Deep merge objects">
    Deep merge multiple objects together.

    <ParamField body="objects" type="any[]" required>
      Array of objects to merge.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "objects": [
        { "theme": "dark", "lang": "en", "notifications": { "email": true } },
        { "lang": "fr", "notifications": { "sms": true } }
      ]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "theme": "dark",
      "lang": "fr",
      "notifications": {
        "email": true,
        "sms": true
      }
    }
    ```
  </Accordion>

  <Accordion title="diff: Compare two objects">
    Find differences between two JSON objects.

    <ParamField body="obj1" type="any" required>
      First object.
    </ParamField>

    <ParamField body="obj2" type="any" required>
      Second object.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "obj1": { "name": "Alice", "age": 30, "city": "Portland" },
      "obj2": { "name": "Alice", "age": 31, "role": "admin" }
    }
    ```

    **Example response:**

    ```json theme={null}
    [
      { "path": "age", "type": "changed", "oldValue": 30, "newValue": 31 },
      { "path": "city", "type": "removed", "oldValue": "Portland" },
      { "path": "role", "type": "added", "newValue": "admin" }
    ]
    ```
  </Accordion>

  <Accordion title="pick: Pick specific keys">
    Extract selected keys from an object.

    <ParamField body="data" type="any" required>
      Source object.
    </ParamField>

    <ParamField body="keys" type="string[]" required>
      Keys to pick.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "data": { "id": 1, "name": "Alice", "email": "alice@example.com", "password": "hashed_pw" },
      "keys": ["id", "name", "email"]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "id": 1,
      "name": "Alice",
      "email": "alice@example.com"
    }
    ```
  </Accordion>

  <Accordion title="omit: Remove specific keys">
    Remove selected keys from an object.

    <ParamField body="data" type="any" required>
      Source object.
    </ParamField>

    <ParamField body="keys" type="string[]" required>
      Keys to remove.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "data": { "id": 1, "name": "Alice", "email": "alice@example.com", "password": "hashed_pw" },
      "keys": ["password"]
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "id": 1,
      "name": "Alice",
      "email": "alice@example.com"
    }
    ```
  </Accordion>

  <Accordion title="get: Get value at path">
    Retrieve a value using dot-notation path.

    <ParamField body="data" type="any" required>
      Source object.
    </ParamField>

    <ParamField body="path" type="string" required>
      Dot-notation path (e.g., `user.address.city`).
    </ParamField>

    <ParamField body="defaultValue" type="any">
      Default value if path not found.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "data": {
        "user": {
          "address": { "city": "Portland", "state": "OR" }
        }
      },
      "path": "user.address.city"
    }
    ```

    **Example response:**

    ```json theme={null}
    "Portland"
    ```
  </Accordion>

  <Accordion title="set: Set value at path">
    Set a value at a dot-notation path.

    <ParamField body="data" type="any" required>
      Source object.
    </ParamField>

    <ParamField body="path" type="string" required>
      Dot-notation path.
    </ParamField>

    <ParamField body="value" type="any" required>
      Value to set.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "data": { "user": { "name": "Alice" } },
      "path": "user.address.city",
      "value": "Portland"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "user": {
        "name": "Alice",
        "address": { "city": "Portland" }
      }
    }
    ```
  </Accordion>

  <Accordion title="minify: Minify JSON">
    Remove all whitespace from a JSON string.

    <ParamField body="json" type="string" required>
      JSON string to minify.
    </ParamField>

    <ParamField body="encoding" type="enum" default="utf8">
      Output encoding for the `result` field: `utf8` (default) or `base64` (for email attachments, SFTP uploads, or knowledge-base embedding). The response includes an `encoding` tag.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "json": "{\n  \"name\": \"Alice\",\n  \"age\": 30\n}"
    }
    ```

    **Example response:**

    ```json theme={null}
    "{\"name\":\"Alice\",\"age\":30}"
    ```
  </Accordion>

  <Accordion title="prettify: Prettify JSON">
    Format a JSON string with indentation.

    <ParamField body="json" type="string" required>
      JSON string to format.
    </ParamField>

    <ParamField body="indent" type="number" default="2">
      Number of indentation spaces.
    </ParamField>

    <ParamField body="encoding" type="enum" default="utf8">
      Output encoding for the `result` field: `utf8` (default) or `base64` (for email attachments, SFTP uploads, or knowledge-base embedding). The response includes an `encoding` tag.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "json": "{\"name\":\"Alice\",\"age\":30}",
      "indent": 4
    }
    ```

    **Example response:**

    ```json theme={null}
    "{\n    \"name\": \"Alice\",\n    \"age\": 30\n}"
    ```
  </Accordion>

  <Accordion title="keys: Get all keys">
    Extract all keys from an object.

    <ParamField body="data" type="any" required>
      Source object.
    </ParamField>

    <ParamField body="deep" type="boolean" default="false">
      Include nested keys with dot-notation.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "data": {
        "name": "Alice",
        "address": { "city": "Portland", "zip": "97201" }
      },
      "deep": true
    }
    ```

    **Example response:**

    ```json theme={null}
    ["name", "address.city", "address.zip"]
    ```
  </Accordion>

  <Accordion title="values: Get all values">
    Extract all values from an object.

    <ParamField body="data" type="any" required>
      Source object.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "data": { "name": "Alice", "age": 30, "active": true }
    }
    ```

    **Example response:**

    ```json theme={null}
    ["Alice", 30, true]
    ```
  </Accordion>

  <Accordion title="validate: Validate JSON string">
    Check if a string is valid JSON.

    <ParamField body="json" type="string" required>
      String to validate.
    </ParamField>

    **Example request:**

    ```json theme={null}
    {
      "json": "{name: 'Alice'}"
    }
    ```

    **Example response:**

    ```json theme={null}
    {
      "valid": false,
      "error": "Expected property name or '}' at position 1"
    }
    ```
  </Accordion>
</AccordionGroup>
