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

131
Views
Parse nested object in JSON string

I have this code:

let test = '{"attribute_as":"plan_id","operator":"fromTo","values":"{"from":"70","to":"80"}"}';
console.log(JSON.parse(test));

It of course fail because in values I have an object. Is there any option how to parse this string in easy way? Or is it not possible at all?

At the end the result should be:

{
    attribute_as: 'plan_id',
    operator: 'fromTo',
    values: {
        from: 70,
        to: 80
    }
}
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

The string is incorrect:

let err = '{"attribute_as":"plan_id","operator":"fromTo","values":"{"from":"70","to":"80"}"}';
// This is the original string
let pass = '{"attribute_as":"plan_id","operator":"fromTo","values":{"from":70,"to":80}}';
// Corrected string

let desiredObj = {
    attribute_as: 'plan_id',
    operator: 'fromTo',
    values: {
        from: 70,
        to: 80
    }
};

console.log(JSON.stringify(desiredObj) == err);
console.log(JSON.stringify(desiredObj) == pass);

about 4 years ago · Juan Pablo Isaza Report

0

This should do the trick. When logged both evaluated correctly.

let
    test = '{"attribute_as": "plan_id","operator": "fromTo","values": {"from": 70,"to": 80}}',
    test2 = {
        attribute_as: 'plan_id',
        operator: 'fromTo',
        values: {
            from: 70,
            to: 80
        }
    }

console.log(JSON.parse(test));
console.log(JSON.stringify(test2));
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!