Skip to content

c.json returning empty string for undefined values #2343

@yusukebe

Description

@yusukebe

Discussed in https://github.com/orgs/honojs/discussions/2338

Originally posted by marcosrjjunior March 11, 2024
I'm mainly creating this ticket to understand a bit more about why this is happening and potentially flag an issue.

One of my functions was returning undefined instead of false and the c.json is forcing the response to be an "" (empty string) instead of throwing an error.
Screenshot 2024-03-11 at 8 51 27 am
Response: ""


Reading the json implementation here (hopefully that is the correct place).

I noticed that there possibly some extra things going on there:

  • JSON.stringify(object). Why do we need to run throguh a JSON.stringify before returning?
  • Re-creating the response

Because of the issues mentioned above I replaced it to use the main response instead.
Screenshot 2024-03-11 at 8 51 36 am

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions