Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

142
Visualizações
How to handle true/false values in JSON object

I have problem where my JSON object has True instead of true and False instead of false. That is causing issues when I parse it to JSON. How do I resolve this issue? In below script obj2 is not working as I have boolean True but not string.

<!DOCTYPE html>
<html>
<body>

<h2>Creating an Object from a JSON String</h2>

    <p id="demo1"></p>
    <p id="demo2"></p>
    
    <script>
    const txt1 =  '{"device_state": {"device_name": "iPhone", "is_phone": true, "is_VOX": false}}'
    const obj1 = JSON.parse(txt1);
    document.getElementById("demo1").innerHTML = obj1.device_state.device_name
    const txt2 =  '{"device_state": {"device_name": "iPhone", "is_phone": True, "is_VOX": false}}'
    const obj2 = JSON.parse(txt2);
    document.getElementById("demo2").innerHTML = obj2.device_state.device_name
    </script>
    
    </body>
    </html>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I can not see what prevents you from assigning "is_phone": true, but if for some reasons it is hard for you , you can change the code to this

var txt2 =  '{"device_state": {"device_name": "iPhone", "is_phone": True, "is_VOX": false}}';
txt2=txt2.replaceAll("True","true").replaceAll("False","false");
const obj2 = JSON.parse(txt2);
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda