Siim withJson() has some character limit to convert an array of objects to Json

Asked

Viewed 112 times

0

I have an array of 700 objects that are being loaded correctly by PHP, but at the time of sending the answer to the browser with the return $response->withJson() the following error is shown:

SyntaxError: JSON.parse: end of data when ',' or ']' was expected at line 1 column 181244 of the JSON data

This error occurs precisely when I need to visualize the 700 objects, when I visualize only 30 objects, for example, the Json is generated correctly.

So I was wondering if $response->withJson() Slim has some character limitation that prevents you from converting this array into a Json. If you have, what would be the best way to view this array in Json format by Slim?

Below is a part of Json that is returned by withJson(), at the end of the Json ] was not added by $response->withJson():

[
    {
        "id":"700",
        "id_usuario":"1",
        "nome":"Empresa 1",
        "cnpj":"00.000.000\/0001-00",
        "contato":"Teste",
        "email":"[email protected]",
        "telefone":"(11)00000000",
        "cidade":"Santo Andr\u00e9",
        "status":"ativado",
        "criado_em":"2016-09-14 10:20:22"
    },
    ...
    {
        "id":"1",
        "id_usuario":"1",
        "nome":"Empresa 2",
        "cnpj":"11.111.111\/0001-11",
        "contato":"Teste 2",
        "email":"[email protected]",
        "telefone":"0000-0000",
        "cidade":"",
        "status":"ativado",
        "criado_em":"2010-12-08 10:20:13"
    }
  • This looks like a JSON formatting error, can you post with 700 elements?? (Edit in your question)

  • 1

    problem is that the error could be anywhere in json, these last 2 objects are correct, so I passed the site that validates json.

  • I cannot put the 700 objects here because each object has more than 10 lines and some contain real information, so I only added the beginning and the end. And it really is formatting problem from what I saw, but it has how to fix it using the $response->withJson() slim’s?

1 answer

0

Actually this is problem in formatting JSON, something left or missing.

I use a website called Jsonlint that already points out where this error, then it is easy to solve.

  • I passed Json on the site and the error is in the last line, was missing the ] to close the array. Now I need to know why the $response->withJson() is not adding the ] at the end of Json.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.