RealFaviconGenerator / realfavicongenerator

Generate favicon for all major platforms
508 stars 23 forks source link

"JSON could not be parsed" but no hint what's wrong #500

Open toolforger opened 4 months ago

toolforger commented 4 months ago

UPDATE: The instructions page does not state what headers need to be set in the header; the error message is misleading. See the comments below for a fix suggestion.

ORIGINAL REPORT:

I can send requests to the API and receive responses, but I keep getting "JSON could not be parsed. Check your syntax." Trouble is, IntelliJ does not see anything wrong with the JSON submitted, I don't either, so the question is: What's wrong?

Here's the JSON request, with the API key redacted because secret:

{ "favicon_generation": { "api_key": "****************************************", "master_picture": { "type": "inline", "content": "PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiIHN0YW5kYWxv bmU9Im5vIj8+CjxzdmcKICAgdmVyc2lvbj0iMS4xIgogICB2aWV3Qm94PSIw IDAgOTIuODU4NTk4IDc1LjQ0Njg1NCIKICAgaGVpZ2h0PSI3NS40NDY4NTRt bSIKICAgd2lkdGg9IjkyLjg1ODU5N21tIgogICBpZD0idG9vbGZvcmdlci1s b2dvIgogICBzb2RpcG9kaTpkb2NuYW1lPSJ0b29sZm9yZ2VyLWxvZ28uc3Zn IgogICBpbmtzY2FwZTp2ZXJzaW9uPSIxLjIuMiAoYjBhODQ4NjU0MSwgMjAy Mi0xMi0wMSkiCiAgIHhtbG5zOmlua3NjYXBlPSJodHRwOi8vd3d3Lmlua3Nj YXBlLm9yZy9uYW1lc3BhY2VzL2lua3NjYXBlIgogICB4bWxuczpzb2RpcG9k aT0iaHR0cDovL3NvZGlwb2RpLnNvdXJjZWZvcmdlLm5ldC9EVEQvc29kaXBv ZGktMC5kdGQiCiAgIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2 ZyIKICAgeG1sbnM6c3ZnPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+ CiAgPGRlZnMKICAgICBpZD0iZGVmczU3MDciIC8+CiAgPHNvZGlwb2RpOm5h bWVkdmlldwogICAgIGlkPSJuYW1l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gIHN0eWxl PSJmaWxsLW9wYWNpdHk6MDtzdHJva2U6IzAwMDAwMDtzdHJva2Utd2lkdGg6 NTtzdHJva2UtZGFzaGFycmF5Om5vbmU7c3Ryb2tlLW9wYWNpdHk6MSIgLz4K ICA8cGF0aAogICAgIGlkPSJhbnZpbC1zaGFwZSIKICAgICBkPSJNIDM5LjI1 NjMyNiwzNS45NDk5NSBIIDkuOTk2NjAxOCBjIDExLjc4NDU2MDIsNS42NDQ5 MSAxOC41NTU2OTAyLDguNTU2NzEgMjQuOTQ1NDg5MiwxMC41NzM2IDIuMzEy NTEzLDAuNTc0MTUgMy4xNzAyNDQsMC44Njg1NCA0LjQ1MDQ1NSwxLjM2NTA1 IDguMDE2LDIuNjY1NzEgMS4wNTEyNTIsMTIuMzI2MTYgLTAuNTAzNDgsMTQu NTQyNzkgbCAwLjAzNjgsMy4wMTU0NiBIIDY5LjYzOTQ3MyBWIDYyLjM5MDM3 IEMgNTYuOTMzNTg4LDQ4LjY1ODAyIDY4LjYyMjI2Miw0NS45MzYwNiA4MC4x MzE2MzYsMzkuNzI0MjcgODEuODA4MjM4LDM4LjkwMjUyIDgyLjc2NDMyLDM3 LjkzNzE5IDgyLjg1ODYsMzcuNTQ1OTUgViAzMi4zNjkzMDIgSCAzOS4xOTk2 NzYgWiIKICAgICBzdHlsZT0iZmlsbC1vcGFjaXR5OjA7c3Ryb2tlOiMwMDAw MDA7c3Ryb2tlLXdpZHRoOjU7c3Ryb2tlLWRhc2hhcnJheTpub25lO3N0cm9r ZS1vcGFjaXR5OjEiIC8+Cjwvc3ZnPgo= " }, "files_location": { "type": "root" }, "favicon_design": { "desktop_browser": {}, "ios": { "picture_aspect": "background_and_margin", "margin": "4", "background_color": "#ffffff", "assets": { "ios6_and_prior_icons": false, "ios7_and_later_icons": true, "precomposed_icons": false, "declare_only_default_icon": true } }, "windows": { "picture_aspect": "as_is", "assets": { "windows_80_ie_10_tile": true, "windows_10_ie_11_edge_tiles": { "small": false, "medium": true, "big": true, "rectangle": false } } }, "firefox_app": { "picture_aspect": "circle", "keep_picture_in_circle": "true", "circle_inner_margin": "5", "background_color": "#ffffff" }, "android_chrome": { "picture_aspect": "no_change", "manifest": { "name": "toolforger", "display": "browser", "start_url": "/" }, "assets": { "legacy_icon": true, "low_resolution_icons": false }, "theme_color": "#ffffff" }, "safari_pinned_tab": { "picture_aspect": "no_change", "theme_color": "#ffffff" }, "open_graph": { "picture_aspect": "no_change" }, "yandex_browser": { "background_color": "#ffffff", "manifest": { "show_title": true, "version": "1.0" } } }, "settings": { "compression": "5", "scaling_algorithm": "Lanczos", "error_on_image_too_small": true, "readme_file": true, "html_code_file": false, "use_path_as_is": false }, "versioning": { "param_name": "v", "param_value": "4" } } }

(Note: line feeds got lost while pasting.)

toolforger commented 4 months ago

I just tried with the example JSON from https://realfavicongenerator.net/api/non_interactive_api and I am still getting the same error.

toolforger commented 4 months ago

WORKAROUND: The instructions on https://realfavicongenerator.net/api/non_interactive_api do not mention the headers needed, and that makes the call fail.

For a fix, I suggest replacing the paragraph "Invoke the service by accessing https://realfavicongenerator.net/api/favicon with a POST method and a JSON document, documented below. The response to this request is similar to the non-interactive API request response." with the following:

Invoke the service as follows:

URI: https://realfavicongenerator.net/api/favicon Headers:

  • content-type: application/json - Not strictly necessary now, but recommended for future compatibility.
  • content-length: - Absolutely required, you will get a JSON parse error if this is not set. Typically set by HTTP libraries, but if yours does not, make sure to use the number of bytes, not the number of characters, which would be an issue with double-byte or international Unicode characters.
  • host: realfavicongenerator.net - Typically automatically set by HTTP libraries, but set it anyway if you get weird error responses. Body: The JSON document, documented below.

    The response to this request is similar to the non-interactive API request response.

UPDATE: Seems like HTTP libraries typically set content-length anyway.