Search code examples
c#amazon-web-servicesasp.net-web-apijson.netamazon-cognito

How to deserialize array of guid ids received from cognito attribute


I have custom attribute in cognito used for mapping third party claims.

After mapping is completed(on user login) I receive values as string in this format

[bf5ad010-8961-49d7-b068-87f23026f49d, 0080d0fe-6a19-4dfe-a472-09a3f93d7015]

I'm trying to deserialize this values on backend to list/array of strings, but since values in [] are not enclosed with "", deserialization fails with error message

''b' is an invalid start of a value. Path: $[0] | LineNumber: 0 | BytePositionInLine: 1.'

Anyone have idea how to handle this?

Thanks


Solution

  • As they are guid-type and custom ids, most likely there will be no other possibility besides this:

    public static class GetClainCognito
    {
        public static IEnumerable<Guid> GetIdClainCognito(this string value) => value.Replace("[", "").Replace("]", "").Split(",").Select(x => Guid.Parse(x));
    }