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

# Data Objects and Attributes

> Inspect and create data objects, attributes, and exceptions in KDDB documents from the kdx CLI, working with the structured data layer of a document.

Commands for working with the structured data layer of a KDDB document. Data objects represent extracted information organized hierarchically, with attributes holding values and exceptions tracking issues.

## Subcommands

| Command                | Description                       |
| ---------------------- | --------------------------------- |
| `data objects`         | List all data objects             |
| `data attributes <id>` | Show attributes for a data object |
| `data exceptions`      | List data exceptions              |
| `data create`          | Create a new data object          |
| `data set-attribute`   | Set an attribute on a data object |

## Data Objects

List all data objects with their path, parent, and attribute counts.

```bash theme={null}
kdx document data objects <file.kddb> [flags]
```

| Flag            | Description                     | Default |
| --------------- | ------------------------------- | ------- |
| `--parent-id N` | Filter by parent data object ID |         |
| `--pretty`      | Pretty-print JSON output        | false   |

```bash theme={null}
kdx document data objects invoice.kddb --pretty
```

```json theme={null}
{"id":1,"path":"INVOICE","attributeCount":3,"childCount":2}
{"id":2,"path":"INVOICE/LINE_ITEM","parentId":1,"attributeCount":4,"childCount":0}
{"id":3,"path":"INVOICE/LINE_ITEM","parentId":1,"attributeCount":4,"childCount":0}
```

## Data Attributes

Show all attributes for a specific data object.

```bash theme={null}
kdx document data attributes <object-id> <file.kddb> [flags]
```

```bash theme={null}
kdx document data attributes 1 invoice.kddb --pretty
```

```json theme={null}
{"id":1,"tag":"vendor_name","value":"Acme Corp","confidence":0.95,"type":"STRING"}
{"id":2,"tag":"invoice_date","value":"2024-01-15","confidence":0.92,"type":"DATE"}
{"id":3,"tag":"total_amount","value":"1234.56","confidence":0.98,"type":"CURRENCY"}
```

## Data Exceptions

List data exceptions (validation errors, extraction issues).

```bash theme={null}
kdx document data exceptions <file.kddb> [flags]
```

| Flag            | Description               | Default |
| --------------- | ------------------------- | ------- |
| `--open`        | Show only open exceptions | false   |
| `--object-id N` | Filter by data object ID  |         |
| `--pretty`      | Pretty-print JSON output  | false   |

```bash theme={null}
kdx document data exceptions invoice.kddb --open
```

```json theme={null}
{"id":1,"message":"Missing required field","exceptionType":"VALIDATION","severity":"ERROR","open":true,"dataObjectId":2,"path":"INVOICE/LINE_ITEM"}
```

## Data Create

Create a new data object in the document.

```bash theme={null}
kdx document data create <file.kddb> --path <data-path> [flags]
```

| Flag             | Description                                                                        | Default |
| ---------------- | ---------------------------------------------------------------------------------- | ------- |
| `--path`         | Data object path (required)                                                        |         |
| `--taxonomy-ref` | Optional data-definition reference used by the current local document command flag |         |
| `--parent-id N`  | Parent data object ID                                                              |         |

```bash theme={null}
kdx document data create invoice.kddb --path "INVOICE/LINE_ITEM" --parent-id 1
```

```json theme={null}
{
  "id": 4,
  "path": "INVOICE/LINE_ITEM"
}
```

## Data Set-Attribute

Create or set a data attribute on a data object.

```bash theme={null}
kdx document data set-attribute <file.kddb> --object-id <id> --tag <name> [flags]
```

| Flag            | Description                                           | Default |
| --------------- | ----------------------------------------------------- | ------- |
| `--object-id N` | Data object ID (required)                             |         |
| `--tag`         | Attribute tag/name (required)                         |         |
| `--value`       | Attribute value                                       |         |
| `--type`        | Attribute type (STRING, CURRENCY, DATE, NUMBER, etc.) | STRING  |
| `--confidence`  | Confidence score (0.0-1.0)                            | 1.0     |
| `--tag-uuid`    | Tag UUID for linking to a tagged node                 |         |

```bash theme={null}
kdx document data set-attribute invoice.kddb \
  --object-id 4 --tag "description" --value "Widget A" --type STRING
```

```json theme={null}
{
  "id": 10,
  "dataObjectId": 4,
  "tag": "description",
  "value": "Widget A",
  "type": "STRING"
}
```

### Linking to Tagged Nodes

Use `--tag-uuid` to connect an attribute to its source node for provenance:

```bash theme={null}
# First, tag the source node
kdx document tag invoice.kddb --node-id 245 --name "line_item/amount"
# Output: {"nodeId":245,"tag":"line_item/amount","tagId":1,"tagUuid":"a1b2c3d4-..."}

# Then link the attribute to the tag
kdx document data set-attribute invoice.kddb \
  --object-id 4 --tag "amount" --value "1234.56" --type CURRENCY \
  --tag-uuid "a1b2c3d4-..."
```

<Tip>
  The `create` and `set-attribute` commands modify the document. They open the file in write mode (non-detached) automatically.
</Tip>

<Tip>
  Use `--tag-uuid` to maintain provenance between extracted values and their source nodes in the document.
</Tip>
