The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates.

godotengine.org | Twitter

0 votes

How do I load a JSON from an URL? I couldn't find anything about that in the documentation.

in Engine by (519 points)

1 Answer

0 votes
Best answer

https://docs.godotengine.org/en/3.0/tutorials/networking/http_request_class.html

extends CanvasLayer

func _ready():
    pass

func _on_Button_pressed():
    $HTTPRequest.request("http://www.mocky.io/v2/5185415ba171ea3a00704eed")

func _on_HTTPRequest_request_completed( result, response_code, headers, body ):
    var json = JSON.parse(body.get_string_from_utf8())
    print(json.result)
by (107 points)
selected by

Thank you! Hope that soon they implement a simpler way, like load_JSON(url).

the problem i could imagine is: that a http request could take a while.
Then you have the problem that this could block the execution of your main thread.
So to me it looks like a common solution you find in nearly every callback based language.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.