0

I'm trying to return an json object from controller's route

return new JsonResponse($result);

It returns

string(36) "e91a6865-b2a8-4b7d-9351-2eac29f7aa30"
{
 //data
}

How can I get rid of the string(36) "e91a6865-b2a8-4b7d-9351-2eac29f7aa30"?

Mikhail Prosalov
4,4134 gold badges35 silver badges43 bronze badges
asked May 28, 2020 at 16:13
7
  • 2
    symfony 4 != symfony 3.4. that being said, looks to me like you have a var_dump somewhere. Commented May 28, 2020 at 16:39
  • No.Actually I'm calling this route via postman Commented May 28, 2020 at 16:42
  • 1
    how you're calling it is completely besides the point. I expect your code to have a var_dump(/dump( somewhere. you probably should look for it Commented May 28, 2020 at 16:43
  • Thanks @Jakumi. There is no var_dump.I've already checked Commented May 28, 2020 at 16:45
  • 2
    Well what can I say, the string(36) "..." is exactly the output a stray var_dump would produce. It might even be in a different file. or something fishy is going on somewhere else. however, it doesn't have anything to do with the JsonResponse. you can check by returning an empty Response, probably. Commented May 28, 2020 at 16:48

1 Answer 1

1

a string(36) "e91a6865-b2a8-4b7d-9351-2eac29f7aa30" or something similar, that wasn't added to the JsonResponse, usually is caused by a stray var_dump/dump call somewhere in the code base (but in a part that gets evaluated).

Essentially what happens: the var_dump/dump is called and it produces the output, and afterwards the output from the Response object (be it the JsonResponse or some other Response) is appended to that.

Options to handle this:

  • remember where you put those calls ;o) (works most of the time)
  • do not commit any var_dump/dump/dd calls to version control ever (and always do version control!), you'll find the calls easily in the git diff.
  • run grep -nr dump src in the project root (on linux obviously, replace dump by dd if appropriate), this should find the relevant locations in code.

However, overall it's a rather benign source of irritating output.

answered May 28, 2020 at 18:01

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.