Forum Discussion

PK_294685's avatar
PK_294685
Icon for Nimbostratus rankNimbostratus
Mar 23, 2017

JSON Base64 Token in iRule

Hello Folks,

 

Did anyone work on generating JSON token on F5? I need the token format as below: {

 

"userid": "mm36",

 

"Name": "Casey",

 

"userid": "12345",

 

"SomeList":

 

[

 

"12345-001",

 

"32124-005"

 

],

 

{

 

"Id": 12345,

 

"queue": 1,

 

"place": "USA"

 

},

 

"userRole": "associate",

 

"levels":

 

[

 

"networkengineer",

 

"analyst",

 

"admin",

 

]

 

}

 

I currently have the below JSON in irule that is working & generating the token. But when i decode the token, i'm not getting the above format. I'm missing the brackets for someLists, Details & levels..

 

set json [b64encode "{\"userid\":\"$userid\",\"Name\":\"$Name\",\"SomeList\":[\"$SomeList\"]\,\"Details\":{\"$Details\"},\"userRole\":\"$userRole\",\"levels\":\"$levels\"}"]

 

Can someone help me if this is the actual way to write a JSON in iRule?

 

Any help is appreciated.. Thanks

 

  • Hi,

    {
    ,
    }
    ,
    [
    and
    ]
    must be escaped.

    set json [b64encode "{\"userid\":\"$userid\",\"Name\":\"$Name\",\"SomeList\":\[\"$SomeList\"\]\,\"Details\":\{\"$Details\"\},\"userRole\":\"$userRole\",\"levels\":\"$levels\"\}"]