kontent-ai / kontent-ai/migration-toolkit

`undefined` is missing from exported JSON

Open
#7 1 comment 0 reactions 1 assignee Claimed by @Enngage View on GitHub
on hold
Dominant language
TypeScript
Stars
4
Forks
3
PR merge metrics
No merged PRs in 30d

Description

### Brief bug description

When data is exported any fields that are set to `undefined` will not be present in the resulting JSON output.

### Repro steps

1. Export a content item that includes an empty field
- Ex: Non-required number element or text element
2. Run the `export` command
3. See that the value field does not exist

### Expected behavior

The `value` field has a value.

### Test environment

N/A

### Additional context

`undefined` is not a valid value [per the JSON specification](https://datatracker.ietf.org/doc/html/rfc7159#section-3).

The [import will gracefully handle a missing `value` field](https://github.com/kontent-ai/kontent-ai-migration-toolkit/blob/b031f4cb996b07a501ec99fcddc2722300a0af6d/lib/translation/transforms/import-transforms.ts#L105). Accessing `data.value` when `value` is missing still results in `undefined`.
However, this can cause issues when a user wishes to directly interact with the exported JSON, expecting the `value` field to exist. Also, values of 0 and an empty string will not be imported correct, resulting in incorrect migrations.

I believe the fix to this issue would be to use `null` instead of `undefined` to represent an empty field.

### Screenshots

![image](https://github.com/user-attachments/assets/5fc14900-af8b-4af3-b0e0-9aebc77405b8)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.