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

204
Views
How to parsing the correct values from a json decoding

Hii ha ve written this question because i have a json converted to a string with a function of php called json_encode()

Something like this:

{ "data":"2","state":"false"}

when the original json that im trying to encode is like this:

{ "data":2,"state":false}

(Please note that the type of the variables are different, in the original i have an int number called data and boolean called state, but when i use json_encode() every variable goes to a string..)

The problem is when i try to json.PARSE() the value from the json encode of php in angular i don´t get the correct value, every variable is a string...

For example, isntead of getting the boolean state of the variable, i get "false" or "true", and this is a problem...

There is a way to parse this avoiding this problem? basically my problem is when i parse the json in my angular project i dont get the correct type of variable..

Thanks!

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

0

You can use JSON.parse on an individual value to convert it into the desired type:

const oldValue = JSON.parse('{"data":"2","state":"false"}')

const result = {}

Object.keys(oldValue).forEach(key => {
  result[key] = JSON.parse(oldValue[key]);
});

Here's the other way around:

const oldValue = JSON.parse('{"data": 2,"state": false}');

const result = {}

Object.keys(oldValue).forEach(key => {
  result[key] = oldValue[key].toString();
});

Note: These examples assume flat objects. You'd need to recurse through the object's tree if some of the values are objects, for example {a: {b: "c"}}.

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!