* Which Category is your question related to? *
Cognito User Attribute Management
* What AWS Services are you utilizing? *
Cognito
* Provide additional details e.g. code snippets *
What format of data should be submitted when setting a user's address attribute? When I submit an object to Auth.updateUserAttributes I can only get it to succeed if I pass in a string. Is it expected that we submit JSON?
I haven't been able to find any documentation regarding this attribute.
const user = await Auth.currentAuthenticatedUser()
const address = {
locality: "New York"
postal_code: "10002"
region: "New York"
street_address: "138 E Broadway"
}
const result = await Auth.updateUserAttributes(user, {
// address // errors
address: JSON.stringify(address) // succeeds
})
The error I get when submitting an object is:
code: "SerializationException"
message: "Start of structure or map found where not expected."
name: "SerializationException"
Hi @lsirivong
What format of data should be submitted when setting a user's
addressattribute? When I submit an object toAuth.updateUserAttributesI can only get it to succeed if I pass in a string. Is it expected that we submit JSON?
address is one of cognito's standard attributes, which are implemented following the OpenID Connect specification. Per the spec, it is a JSON string:
address | JSON object | End-User's preferred postal address. The value of the聽address聽member is a JSON聽[RFC4627]聽structure containing some or all of the members defined in聽Section聽5.1.1.
-- | -- | --
I just tried copy-pasting your code as-is in a test app and the attribute was successfully updated. I am not sure what could be wrong. Do you have a more detailed stack trace?
I must have overlooked that the specification said JSON object. I was expecting the API to expect an actual object.
Thanks for confirming that it should be JSON.
What is a JSON object? That sounds like bad documentation imo.
Most helpful comment
Hi @lsirivong
addressis one of cognito's standard attributes, which are implemented following the OpenID Connect specification. Per the spec, it is a JSON string:address | JSON object | End-User's preferred postal address. The value of the聽address聽member is a JSON聽[RFC4627]聽structure containing some or all of the members defined in聽Section聽5.1.1.
-- | -- | --
I just tried copy-pasting your code as-is in a test app and the attribute was successfully updated. I am not sure what could be wrong. Do you have a more detailed stack trace?