Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

97
Views
After posting JSON with jQuery, convert the string back into a JSON

So I have some code that posts this JSON:

post = {
    period: "1",
    data: {1: "Here"}
}

And it is posted with this code:

$.ajax({
    url: 'http://127.0.0.1:5000/',
    data: post,
    type: 'POST'
})

When I execute this code, my server receives this string: "period=1&data%5B3%5D=Here"

Is there a way to convert this string back into a JSON?

I have tried JSON.parse() but that obviously did not work.

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

It was never JSON, you can send it as JSON by using JSON.stringify and then use JSON.parse to get it back as an object on the server.

$.ajax({
    url: 'http://127.0.0.1:5000/',
    data: JSON.stringify(post),
    contentType: 'application/json',
    type: 'POST'
})
about 4 years ago · Juan Pablo Isaza Report

0

You can parse the string with the URLSearchParams constructor, then use Object.fromEntries to convert it to an object:

const obj = Object.fromEntries(new URLSearchParams("period=1&data%5B3%5D=Here"));
console.log(obj)

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!