Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to convert application/x-www-form-urlencoded to JSON using javascript

Hi, I  just want to have an option to apply JSON validation in application/x-www-form-urlencoded requests. Thanks.

Solved Solved
0 2 4,633
1 ACCEPTED SOLUTION

Hi Dino,

I already find the answer about this question. Thanks for attending on our questions.

Here is what I found and it works. Hope it helps others also. It applies also on query parameters. Just replace "request.formstring" with "request.querystring".

var formRequest = context.getVariable("request.formstring").split("&");
formRequest.forEach(function(keyValuePair) {
	var nameAndValue = nameValuePair.split('=');
	jsonOutput += '"' + nameAndValue[0] + '"' + ':' + '"' + nameAndValue[1] + '"' + ',';
});
Output = '{' + Output.substr(0, Output.length -1) + '}';
context.setVariable('request.content', Output);

 

 

View solution in original post

2 REPLIES 2
Top Solution Authors