# Get user\_metadata in jwt

**URL:** <https://community.auth0.com/t/get-user-metadata-in-jwt/74450>\
**Category:** Get Help\
**Tags:** jwt\
**Created:** [December 8, 2021, 6:11am UTC](https://community.auth0.com/t/get-user-metadata-in-jwt/74450 "2021-12-08T06:11:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jerryforcode](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jerryforcode/32/32084_2.png) [@jerryforcode](https://community.auth0.com/u/jerryforcode)\
**Post date:** [December 8, 2021, 6:11am UTC](https://community.auth0.com/t/get-user-metadata-in-jwt/74450/1 "2021-12-08T06:11:07Z")

</div>

Hi @SaqibHussain

How can i obtain the user\_metadata in the id token?  
i’ve tried this:  
`context.idToken["mydomainnamespace/user_metadata"] = user.user_metadata;`

but when i go to [jwt.io](http://jwt.io) to decode the token, the user\_metadata doesn’t appear.

Please advise.

Regards,  
Jerry

---

<div class="post-metadata">

**Author:** ![SaqibHussain](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/saqibhussain/32/42924_2.png) [@SaqibHussain](https://community.auth0.com/u/SaqibHussain)\
**Post date:** [December 8, 2021, 1:48pm UTC](https://community.auth0.com/t/get-user-metadata-in-jwt/74450/2 "2021-12-08T13:48:35Z")

</div>

Hi @jerryforcode

You’re on the right lines there, you’ll need to specify the property/object you want to extract e.g. with user\_metadata like this:

```auto
{
  "preferences": {
    "year": "1985",
    "genre": "family"
  }
}

```

You might have a rule like this to extract the preferences:

```auto
function (user, context, callback) {
	if((user.user_metadata || {} ).preferences){
		context.idToken['https://mynamespace/preferences'] = user.user_metadata.preferences;
	}
	callback(null, user, context);
}

```

I hope this helps.  
Regards

---

<div class="post-metadata">

**Author:** ![jerryforcode](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jerryforcode/32/32084_2.png) [@jerryforcode](https://community.auth0.com/u/jerryforcode)\
**Post date:** [December 9, 2021, 3:45am UTC](https://community.auth0.com/t/get-user-metadata-in-jwt/74450/3 "2021-12-09T03:45:44Z")

</div>

thank you for clarifying that!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 9, 2021, 9:54am UTC](https://community.auth0.com/t/get-user-metadata-in-jwt/74450/4 "2021-12-09T09:54:43Z")

</div>

We are here for you!

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [December 22, 2021, 3:19pm UTC](https://community.auth0.com/t/get-user-metadata-in-jwt/74450/5 "2021-12-22T15:19:41Z")

</div>


