Skip to content

fix: emit null instead of empty string in JSON output - #16

Merged
julianschiavo merged 1 commit into
mainfrom
fix/json-nil-coercion
Mar 13, 2026
Merged

fix: emit null instead of empty string in JSON output#16
julianschiavo merged 1 commit into
mainfrom
fix/json-nil-coercion

Conversation

@julianschiavo

@julianschiavo julianschiavo commented Mar 13, 2026

Copy link
Copy Markdown
Member
  • Changed DocumentationSearchDocument.contents and .title from String (defaulting nil to "") to String? so JSON output emits null for missing values
  • Added custom encode(to:) to ensure nil optionals are always serialized as null keys rather than omitted
  • Added regression tests in SearchJSONOutputTests verifying null emission and non-nil preservation

Note

Low Risk
Low risk: only changes CLI JSON encoding of title/contents from empty strings to explicit null, plus adds focused regression tests.

Overview
Updates the search --json output to preserve missing fields as JSON null by making DocumentationSearchDocument.title/contents optional and encoding them explicitly (instead of coercing nil to empty strings or dropping keys).

Adds SearchJSONOutputTests to verify nil values serialize as null and non-nil values remain unchanged.

Written by Cursor Bugbot for commit b13e8af. This will update automatically on new commits. Configure here.

@julianschiavo
julianschiavo force-pushed the fix/json-nil-coercion branch from d56296e to bc06581 Compare March 13, 2026 05:49

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Comment thread Sources/XCDocsCLI/SearchCommand.swift Outdated
Comment thread Tests/XCDocsCLITests/SearchJSONOutputTests.swift Outdated
@julianschiavo
julianschiavo force-pushed the fix/json-nil-coercion branch from bc06581 to b13e8af Compare March 13, 2026 05:57
@julianschiavo
julianschiavo merged commit c2ef4ad into main Mar 13, 2026
3 checks passed
@julianschiavo
julianschiavo deleted the fix/json-nil-coercion branch March 13, 2026 06:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant