Brian Dunning's FileMaker Custom Functions

readJWTbody ( )

Reads the body of a Javascript Web Token (JWT)

  Be the first to rate this function Log in to vote

David A Sullivan   David A Sullivan - Show more from this author
Mandelbrot LLC

Share on Facebook Share on Twitter

  Sample input:
readJWTbody ( "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIjoic3ViamVjdCIsIm5hbWUiOiJEVU1NWSBUb2tlbiIsImlhdCI6MTYxMDAwMDAwMH0.qPw_WZTWQJEmvjdyrKzfNKOvBuHqtVtOHoaD88Y62SY" )
  Sample output:
{"sub":"1234567890":"subject","name":"DUMMY Token","iat":1610000000}

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

A JavaScript Web Token (JWT) is three parts: a header, a body, and a signature. These three parts are base64 encoded, then separated by dots. Many times, it is useful to decode the middle section, (body) which can contain things like the scope of access granted to the token bearer, or the name of the account used to generate the token.

However, FileMaker's base64decode() function sometimes chokes on decoding that middle section. This is due to the fact that base64 is a 6-bit encoding scheme. In order to decode base64 to binary (which is encoded in 8-bit bytes) base64 must have padding added to the end if it does not contain a number of bits that adds up to a multiple of 24.

In other words:
Binary has 8 bits per unit, and base64 has 6 bits per unit, so if you land on something that's not a multiple of 24 bits, FileMaker's base64decode doesn't know what to do with the remainder. you have a handful of indecipherable bits, so FM returns a ?. So, I wrote this handy custom func to add "=" symbols, also known as "padding".

Updated 2023-10-16 to accept Base64url (special thanks to Josh Willing Halpern)



Log in to post comments.


Note: these functions are not guaranteed or supported by Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 19 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: