arnav-kr / json-formatter

A Browser Extension to format JSON in the browser automatically. Available with 60+ Themes, Syntax Highlighting, automatically linkifies links and more.
https://json-formatter.js.org
MIT License
71 stars 13 forks source link

Bug: Some complex JSON cannot be parsed #24

Closed BigHeadDev closed 2 months ago

BigHeadDev commented 8 months ago

Is there an existing issue for this?

Describe the bug

a complex json

You can try this URL~~~

Expected Behavior

No response

Steps To Reproduce

No response

System Info

- OS:
- Browser:

Additional context?

No response

arnav-kr commented 2 months ago

can you provide another working url? this one seems to be down

BigHeadDev commented 2 months ago

can you provide another working url? this one seems to be down https://[cj.lziapi.com/api.php/provide/vod/from/lzm3u8?ac=detail&ids=79752](https://cj.lziapi.com/api.php/provide/vod/from/lzm3u8?ac=detail&ids=79752)

arnav-kr commented 2 months ago

Hi, thanks for providing the new URL, I checked it and found, it is the issue with the API provider, the response that they give contains a property vod-content which contains valid HTML content, and they are setting the content-type as text/html in the response, so when the browser (not the extension) gets the response, it tries to render that valid HTML, and thus breaking the valid JSON structure and as JSON Formatter can only get content from the page's HTML, it sees the same that browser sees, and ignore formatting due to invalid JSON.

JSON being rendered partially as HTML

Fixes:

BigHeadDev commented 2 months ago

Hi, thanks for providing the new URL, I checked it and found, it is the issue with the API provider, the response that they give contains a property which contains valid HTML content, and they are setting the as in the response, so when the browser (not the extension) gets the response, it tries to render that valid HTML, and thus breaking the valid JSON structure and as JSON Formatter can only get content from the page's HTML, it sees the same that browser sees, and ignore formatting due to invalid JSON.vod-content``content-type``text/html

JSON being rendered partially as HTML

Fixes:

  • if you are the creator of the API, just set in response headers, and the browser will see it as JSON and will not try to render the HTML part, and JSON Formatter should work fine in that case.content-type: application/json
  • If you are the consumer, best you can do is reporting them, as even without JSON Formatter, if you copy the response displayed in the browser, it'd be corrupt JSON

ok thanks for your replying~~