Search code examples
jmeterbase64preprocessor

How can i convert Json request to base 64 in JMeter Preprocessor


I have a following Json

Ex : var Jsonfile = [ { "value": "3", "type" : "string", "label: "Repaymentday" },

{ "value": "3", "type" : "string", "label: "Repaymentday" }, ];

i need to store all this requests in a single variable and i need to convert those values as Base64. i am adding all this request in Preprocessor and i need to pass this variable into JMeter request(as base64 value). Could someone please how to achieve this in JMeter


Solution

    1. There is __base64Encode() function available in Custom JMeter Functions bundle (can be installed using JMeter Plugins Manager) which can perform the encoding of arbitrary text (or JMeter Variable)

      ${__base64Encode(foo,)}
      
    2. If you don't want or cannot use JMeter Plugins you can do the same using JMeter's built-in __groovy() function like:

      ${__groovy('foo'.bytes.encodeBase64().toString(),)}
      

    Replace foo with the actual text you want to encode and that would be it

    enter image description here