Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

205
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda