1

I am getting the following string in my request body:

params%5Bparam1%5D=543543&params%5Bparam2%5D=fdasghdfghdf&params%5Btest%5D=yes

How can I translate this to normal JSON?

This is the request body parsed to Lambda Proxy from API gateway.

hackerrdave
  • 5,946
  • 1
  • 23
  • 28
Pano
  • 1,769
  • 4
  • 15
  • 23

1 Answers1

1

If you want something quick and dirty in JavaScript (modified from this related answer)

let params = "params%5Bparam1%5D=543543&params%5Bparam2%5D=fdasghdfghdf&params%5Btest%5D=yes";

let result = JSON.parse('{"' +
  decodeURIComponent(params)
    .replace(/"/g, '\\"')
    .replace(/&/g, '","')
    .replace(/params\[/g, '')
    .replace(/\]=/g, '=')
    .replace(/=/g, '":"') +
  '"}');

console.log(result);
Community
  • 1
  • 1
Josh Bowden
  • 5,231
  • 2
  • 21
  • 35