# Compare a JSON with a JSON

## Overview

This procedure compares two JSON objects and identifies the differences between them. It returns a list of keys where the values differ between the two objects, including keys that exist in one object but not the other. The comparison is performed at the top level of the JSON objects.

## Input

| Concept | Type | Description                           | Required | Default |
| ------- | ---- | ------------------------------------- | -------- | ------- |
| target  | json | The first JSON object to be compared  | Yes      | N/A     |
| object  | json | The second JSON object to be compared | Yes      | N/A     |

## Output

| Concept     | Description                                                                                                                                     |
| ----------- | ----------------------------------------------------------------------------------------------------------------------------------------------- |
| differences | A list of keys where the values differ between the two JSON objects. Each difference is represented as a string indicating the key that differs |

## Examples

### 1. Comparing simple JSON objects with one difference

This example compares two JSON objects and identifies that the "age" field differs.

```kog
set the target to
    {
        "name": "John",
        "age": 30,
        "city": "New York"
    }
set the object to
    {
        "name": "John",
        "age": 31,
        "city": "New York"
    }
compare the target json with the object json
```

### 2. Comparing nested JSON objects

This example compares two JSON objects with nested structures. Note that the comparison identifies "specs" as different (since the nested object differs), not the individual nested fields.

```kog
set the target to
    {
        "product": "Laptop",
        "price": 1200,
        "specs": {
            "RAM": "16GB",
            "Storage": "512GB SSD"
        }
    }
set the object to
    {
        "product": "Laptop",
        "price": 1200,
        "specs": {
            "RAM": "8GB",
            "Storage": "256GB SSD"
        }
    }
compare the target json with the object json
```

### 3. Complete comparison workflow with result handling

This example demonstrates a complete workflow: loading two JSON objects (where the actual json might be `{"name": "john", "age": 28}` and expected json is `{"name": "john", "age": 29}`), comparing them, and storing the list of differences (\["age"]) in a fact for later use.

```kog
get the actual json
get the actual json as a json
the actual json is a json
get the expected json
get the expected json as a json
the expected json is a json
compare the expected json with the actual json
use the above as the keys
the keys
```


---

# 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://docs.kognitos.com/legacy/legacy-experience/automation-areas/summary-1/to-open-a-json-at-a-file/to-compare-a-json-with-a-json.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.
