How do i load an external JSON file?

How do I…

I want to load a JSON file

What is the expected result

Being able to display the JSON file for further manipulation
When i clic on the “GetJson” button,

  • I want to get the firebase storage URL of the file (this is working)
  • Then i want to transform the Json File into a Scene file (not working)

What is the actual result

I don’t get errors while looking at the callback variable, but the json is not loaded

Here is the code i use

Here is the Json file URL :
https://firebasestorage.googleapis.com/v0/b/coloryage-b68ad.firebasestorage.app/o/armor.json?alt=media&token=be1c4b9e-d62f-4aa0-ae75-a7e462d01232

I tried with a “NetWork” GET but i’m not sure to properly define it :

@MrMen any idea ? You usually of great help :smiley:

I had to google and ChatGPT this one, but I have a result. It took a few hours to realise it seems like the “Network Request from URL” action was not handling the request correctly. I resorted to a javascript solution instead:


With the variables:


And output:


Javascrpt code:

const url = runtimeScene.getVariables().get("armour_url").getAsString();

fetch(url)
  .then(response => {
    if (!response.ok) {
      throw new Error(`HTTP error ${response.status}: ${response.statusText}`);
    }
    return response.json(); 
  })
  .then(data => {
    runtimeScene.getVariables().get("armourData").fromJSObject(data);

    runtimeScene.getVariables().get("callback").setString("OK");
  })
  .catch(error => {
    runtimeScene.getVariables().get("callback").setString(error.message);
  });

Wow… nice work.
I’m still having trouble to get it.

I don’t understand what is this event ? “Declare parsed_json…”

And you have variables as Text, but it turn out your need to display JSON at the end… when does this happen ?

Thanks for the help 100 times @MrMen

Ah, my bad. It was a local variable I was using to try something else out. Ignore it, it shouldn’t be there.


ArmourData is initially declared a text, but it becomes a structure when it’s set in the javascript line "fromJSONObject(data)". That’s a neat (and sometimes frustrating) feature of GDevelop - it’s not strongly typed.

The action "ToJSON(ArmoutData)" converts it to a text string.

Just for your information,

I was still having hard time to get the file content … I spend hours with ChatGPT, he told me that it may be CORS issues to access the file… I change the hosting of this file to control easily this CORS issue, AND i finally got it !

However… you reach to have the proper output right ? What browser do you use ? (i even reuse the same variable name to be sure i’m doing exactly what you suggest)

Yes, I appear to get the correct data. I use Opera, but I don’t think that influences GDevelop.