fix(custom-fields): preserve JSON objects/arrays in --custom values#976
Open
Hernanduno wants to merge 2 commits intoankitpokhrel:mainfrom
Open
fix(custom-fields): preserve JSON objects/arrays in --custom values#976Hernanduno wants to merge 2 commits intoankitpokhrel:mainfrom
Hernanduno wants to merge 2 commits intoankitpokhrel:mainfrom
Conversation
added 2 commits
April 2, 2026 22:40
Problem
Custom fields provided via --custom were always treated as plain strings in key paths that needed structured payloads. This broke User Picker fields (single and multi) and other custom fields requiring nested objects because Jira expected a JSON object/array, not an escaped string.
Motivation
Users editing issues with commands like the one below would hit Jira validation errors even when passing valid JSON.
Example command (values anonymized)
jira issue edit DEMOSERVICES-16216 --custom 'code-reviewer={"name":"redacted.user@example.com"}' --no-input
Before this fix (internal payload sent)
"customfield_xxxxx": [{"set": "{\"name\":\"redacted.user@example.com\"}"}]
After this fix (internal payload sent)
"customfield_xxxxx": [{"set": {"name": "redacted.user@example.com"}}]
What changed
- Added a dedicated parser in pkg/jira/customfield_parser.go that detects JSON containers (object/array) and unmarshals them while preserving existing behavior for non-container primitives/strings.
- Wired create flow to pass parsed object/array directly into fields payload (instead of forcing string).
- Wired edit flow to emit set operations with any typed value (object/array) so Jira receives correct structured JSON.
- Kept pkg/jira/customfield.go focused on type declarations; parser logic is now isolated in its own file.
Testing
- Added unit tests in pkg/jira/customfield_json_test.go for create and edit with deeply nested JSON structures.
- Verified with: go test ./pkg/jira
Replace negated OR condition with equivalent De Morgan form to satisfy golangci-lint/staticcheck in CI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Custom fields provided via --custom were always treated as plain strings in key paths that needed structured payloads. This broke User Picker fields (single and multi) and other custom fields requiring nested objects because Jira expected a JSON object/array, not an escaped string.
Motivation
Users editing issues with commands like the one below would hit Jira validation errors even when passing valid JSON.
Example command (values anonymized)
jira issue edit DEMO-16216 --custom 'code-reviewer={"name":"redacted.user@example.com"}' --no-input
Before this fix (internal payload sent)
"customfield_xxxxx": [{"set": "{"name":"redacted.user@example.com"}"}]
After this fix (internal payload sent)
"customfield_xxxxx": [{"set": {"name": "redacted.user@example.com"}}]
What changed
Added a dedicated parser in pkg/jira/customfield_parser.go that detects JSON containers (object/array) and unmarshals them while preserving existing behavior for non-container primitives/strings.
Wired create flow to pass parsed object/array directly into fields payload (instead of forcing string).
Wired edit flow to emit set operations with any typed value (object/array) so Jira receives correct structured JSON.
Kept pkg/jira/customfield.go focused on type declarations; parser logic is now isolated in its own file.
Testing
Added unit tests in pkg/jira/customfield_json_test.go for create and edit with deeply nested JSON structures.
Verified with: go test ./pkg/jira