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

145
Vistas
making a json object in php that is parsable by javascript

I have a huge list of things with each of those things broken down into four sub-things. I am easily able to gather them in nested arrays in PHP, but when I use json_encode to pass them as a JSON object to my javascript client side, the JSON.parse() function always fails because my data is filled with all kinds of entities like ' / \ " & % {} []

It's a shame there is no constant that you can add to json_encode to ensure it's javascript ready.

What characters must I escape or otherwise deal with to ensure I get a javascript parsable object. I was unable to find one. I could easily write a function to handle this if I knew which characters to deal with.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There should be no problem with your approach. Maybe there is a problem when rendering the data? Did you try the following to output the json?

echo 'var myjs = ' . htmlspecialchars(json_encode($obj)) . ';';

If you render the json in a different url/endpoint you do not have to encode anything yourself. However you should make sure your http headers are set correctly

header('Content-Type: application/json');
echo json_encode($obj);
die(0); # thx for requesting my endpoint
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