You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
crw
changed the title
Bug (or at least misleading error message) in jsondecode function when there is dupplicate keys in given json string
Bug (or at least misleading error message) in jsondecode function when there is duplicate keys in given json string
Jan 16, 2025
Thanks for this issue report. I would imagine this would come from the upstream library provided by golang, it might be worth investigating whether there is an upstream bug for this issue. Thanks!
Yes, the error is coming from an upstream library, though not the Go standard library, but rather the go-cty library used to handle the underlying type system in Terraform. The problem stems from Terraform (cty) being mostly statically typed, and trying to decode multiple values of different types into a single object key.
Because duplicate keys are conventionally tolerated in json decoding rather than failing, the decoding library attempts to override the first object encountered with the second, but it cannot decode the second object due to it having a different type -- {test=string} is distinct from {test2=string}.
That explains why the error is what it is, but you're right that is not a helpful error. We'll have to see if the upstream library can refactor the decoding a bit to give a more useful message.
Terraform Version
Terraform Configuration Files
Does not work :
Works :
Debug Output
During plan or apply :
Expected Behavior
The dupplicate key should overwrite the previous ones in the map, or at least the error message should state why is "test" unsupported.
Actual Behavior
It fails saying that "test" (the dupplicate key) is an unsupported attribute
Steps to Reproduce
Additional Context
No response
References
No response
Generative AI / LLM assisted development?
No response
The text was updated successfully, but these errors were encountered: