Dear all,

I'm following the documentation to send an HTTP request to a server. Here is the documentation:

    func _make_post_request(url, data_to_send, use_ssl):
        # Convert data to json string:
        var query = JSON.print(data_to_send)
        # Add 'Content-Type' header:
        var headers = ["Content-Type: application/json"]
        $HTTPRequest.request(url, headers, use_ssl, HTTPClient.METHOD_POST, query)

In my own code, I'm building the data to send with a Dictionary.

if OS.get_name() == "HTML5":
		var headers = ["Content-Type: application/json"]
		var data : Dictionary
		data = { "score": score , "round" : round_number, "gameOver" : game_over }
		request(server_path, headers, true, HTTPClient.METHOD_POST, JSON.print(data))

It works fine and the server receive the data. But doing that, I constantly have an error message in my browser console:

Could you explain me please what is wrong ? Many thanks.

7 days later

Hi there, nobody knows something about this issue ?

Have you done a web search for that error message? I would do it, but that's an image and I don't want to type in all the text.

5 days later

Hi, thanks for the answer. I tried googling ERROR: Error parsing JSON at line 0: at: parse (core/bind/core_bind.cpp:3216) - Error parsing JSON at line 0:

but no success. There are some similar issues but I don't see a clear solution. I tried with the last version (3.4.2) and the error still occurs.

Thanks for your help.

Do you know if the issue on the Godot side or the web browser side? If it's the Godot code then it might be the JSON getting passed to it have minor formatting issues that can be fixed with some preprocessing before parsing.

a month later

What do you mean by in Godot side or in browser side ? Actually this code is only performed in HTML5 target (if OS.get_name() == "HTML5") so I can only see it in my browser. Since the "request" function is not usable in Godot standalone mode, I can't reproduce into Godot.

A mistake in JSON..... hum ...... I don't know what could be the issue..... the JSON is this one:

var data : Dictionary
        data = { "score": score , "round" : round_number, "gameOver" : game_over }
         JSON.print(data)

So, it's actually computed in the code via JSON.print, and I use a Dictionary to do so.

Thanks for your help

Can you show the result of JSON.print(data)? It might be an issue with the objects or how they are serialized. The code you posted looks correct.

@stalex said: What do you mean by in Godot side or in browser side ? Actually this code is only performed in HTML5 target (if OS.get_name() == "HTML5") so I can only see it in my browser. Since the "request" function is not usable in Godot standalone mode, I can't reproduce into Godot.

I was just curious if it was being parsed on the browser (Javascript or a web server) or entirely through Godot. My hunch was that it could have been the JSON being sent or received was in a different format than Godot's JSON, and so the potentially minor difference in how it was formatted was causing the issue.

Yes, that can definitely be the problem and will be easier if we can see the output from the print statement.

7 days later

Hi, here is the output of such JSON data computed during the game run:

> {"score":12,"round":1,"gameOver":false}

I can't see my mistake... :( Even better, here is the copy of the log in Chrome when I'm executing the game in HTML5 target:

You can see the JSON data printed, and just after, the error.

Thanks a lot for your help !

Strange. That looks like valid JSON. And I just tested it and don't see any problem in Godot.

10 months later