title: How to map MapUniqueJsonKey for Json Claim Type
body: <p>I am using Identity Server 4 and UserProfileService to provide the custom claims for user.</p>
  
  <p>There are two scenarios to cover:</p>
  
  <ol>
  <li>Mvc application needs to get access to UserClaims via middleware</li>
  <li>Other non .Net application needs to get access to UserClaims (Eg. Postman or React)</li>
  </ol>
  
  <p>I tried two ways but still couldn't achieve both above requirements:</p>
  
  <p><strong>Method 1</strong>: Using <code>IdentityServerConstants.ClaimValueTypes.Json</code></p>
  
  <p>In UserProfileService.cs, I added the claims like below:</p>
  
  <pre><code>var roles= new List&lt;string&gt;
  {
      "products.read", "products.write", "products.delete"
  };
  
  claims.Add(new Claim("roles", JsonConvert.SerializeObject(roles), IdentityServerConstants.ClaimValueTypes.Json));
  </code></pre>
  
  <p>I generated the AccessToken and send the request to UserInfoEndpoint.  I got the following result successfully:</p>
  
  <pre><code>{
      "user_id": "950d44f1-d19e-412b-9fad-e0b59c11b2ec",
      ...
      "roles": [
          "products.read",
          "products.write",
          "products.delete"
      ],
      "sub": "950d44f1-d19e-412b-9fad-e0b59c11b2ec"
  }
  </code></pre>
  
  <p>Then, I added this in the Mvc application\Startup.cs</p>
  
  <pre><code>options.ClaimActions.MapUniqueJsonKey("roles", "roles", "json");
  </code></pre>
  
  <p>However, in my Mvc application, I got the error and it couldn't deserialize the roles array in the claim.</p>
  
  <pre><code>InvalidCastException: Cannot cast Newtonsoft.Json.Linq.JArray to Newtonsoft.Json.Linq.JToken.
  Newtonsoft.Json.Linq.Extensions.Convert&lt;T, U&gt;(T token)
  </code></pre>
  
  <p><strong>Method 2</strong>: Without Using <code>IdentityServerConstants.ClaimValueTypes.Json</code></p>
  
  <p>If I removed IdentityServerConstants.ClaimValueTypes.Json) when adding the claim types, it works in MVC app.  But it is showing as string in the postman instead of the Json object.  See below:</p>
  
  <pre><code>{
      "user_id": "950d44f1-d19e-412b-9fad-e0b59c11b2ec",    
      "permissions": "[\"products.read\",\"products.write\",\"products.delete\"]",
      "sub": "950d44f1-d19e-412b-9fad-e0b59c11b2ec"
  }
  </code></pre>
  
  <p>I'm just wondering, is it by design or did I do something wrong?  </p>
  
  <p>Is there anyway to keep the claims in Json format and make Mvc claims mapping work for Array of strings in Claim?</p>