Mjml: API sometimes returns invalid JSON

Created on 21 Oct 2019  路  15Comments  路  Source: mjmlio/mjml

Describe the bug
The MJML API sometimes returns invalid JSON when attempting to render MJML as HTML.

To Reproduce
Steps to reproduce the behavior:

  1. Render MJML to HTML via the API.
  2. Decode returned JSON (containing HTML) via PHP json_decode.
  3. Receive PHP error: Control character error, possibly incorrectly encoded.
    I'm happy to share an example of invalid JSON response privately. Just let me know the best way to get it to you.

Expected behavior
Valid JSON should have been returned.

MJML environment (please complete the following information):
API

Additional context
The invalid JSON is not returned with every API call. Rendering some emails works fine while others consistently return invalid JSON.

Most helpful comment

Hello guys, I've found the problem.

the problem is indeed between the go & node, when the node have processed the query, go doesn't read fully the message ( seems to be after a certain amout of weight ) I've the fix and it will soon gonna be released.

thanks @intelliweb for bringing that up !

All 15 comments

Hi @intelliweb thanks for reporting this, could you please provide an example of an email that return invalid Json ?

By the way I would suspect this is not random, but rather depending on the payload you actually send.

Rendering some emails works fine while others consistently return invalid JSON.

I suppose you're sending some content that varies from one time to the other, maybe user-generated emails? I'd start there and see if that could be where the invalid characters are coming from. This is the first time this is raised in years and there's absolutely no reason for the API to randomly return wrong characters.

This has been reported here too #1637

Alright, never got an answer on this one so I still suspect it's due to the input sent but let's see :-)

@kmcb777 Please find the request and response JSON here:
https://gist.github.com/intelliweb/c9a14f61cf2bd16b8d5e31b587b80de7

@ngarnier Yes, it is probably related to the content. Some of the content does vary with each email. I just can't figure out what in the email would cause the issue. The request is valid JSON according to jsonlint.com

Let me know if I can do anything else to help.

@intelliweb Does the provided json will 100% output a invalid json ?

@iRyusa - Sorry, I don't understand the question.

With this JSON here: https://gist.github.com/intelliweb/c9a14f61cf2bd16b8d5e31b587b80de7#file-request-json does the api will always return an invalid JSON?

@iRyusa Yes. Every time I have tried with the API it has returned invalid JSON.

@iRyusa After running several times without issue, this has happened again with a different email. Same overall template but different content within the template. I've included the request and response JSON in the Gist as request2.json and response2.json

https://gist.github.com/intelliweb/c9a14f61cf2bd16b8d5e31b587b80de7

Any ideas?

Both responses have exactly the same length, that's interesting... we'll check that, it might be an issue between go & node

Hello guys, I've found the problem.

the problem is indeed between the go & node, when the node have processed the query, go doesn't read fully the message ( seems to be after a certain amout of weight ) I've the fix and it will soon gonna be released.

thanks @intelliweb for bringing that up !

Awesome. Thank you @Tommy-42 !

sorry for the delay @intelliweb, the fix has been released, you should now be able to send your payload without any problem !

if you don't see any error I will let you close the issue :)

Thanks so much @Tommy-42
Sounds like we should be all good now. Since this was a sporadic issue that we only saw once a month or less with certain emails, you may want to just close it out now. I'll reach back out if we encounter any other errors.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ghost picture ghost  路  4Comments

plaisted picture plaisted  路  4Comments

hellfish2 picture hellfish2  路  4Comments

tobystokes picture tobystokes  路  3Comments

iwanaga-sakura picture iwanaga-sakura  路  4Comments