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
  • 6,486
  • 1
  • 25
  • 29
Pano
  • 2,099
  • 6
  • 16
  • 24

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,735
  • 2
  • 25
  • 36