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

180
Visualizações
JSON.parse works only after re-render in React/Next

I have an object called organizationCustomizationOptions, which is a String. If I print that string without parsing it, I will get something like '{"name":"John", "age":30, "city":"New York"}'

Please note that I'm changing the actual JSON which is something way more complex to this simple example from W3 Schools. The only difference might be that the real JSON contains line breaks and HTML tags inside. I've already dealt with that by adding a dangerouslySetInnerHTML prop inside the

tag into which I want to put a text in and my own CSS classes. The line breaks and HTML tags inside the string might be out of scope of this problem, but just wanted to give the info just in case.

If I try to console.log(JSON.parse(organizationCustomizationOptions)) I get SyntaxError: Unexpected token u in JSON at position 0. However If I comment this line, render the app, and then uncomment, everything works perfectly.

This is obviously not happening with the simple object in the example. It's happening with the big, complex object that has line breaks and HTML tags inside.

about 4 years ago · Juan Pablo Isaza
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