Skip to content

How to parse JSON in Godot 4: JSON.parse_string()

By Eduardo Orellana · Updated

JSON.parse_string(text) returns the parsed Dictionary or Array, or null when the text is not valid JSON. Godot 3's JSON.parse(text).result fails to parse in Godot 4 with Cannot call non-static function "parse()" on the class "JSON" directly. Make an instance instead.

AppImage, x86_64. Ubuntu 22.04, Debian 12, Fedora 39 or newer.

Intel or AMD Chromebook, with Linux turned on.

Download for macOSDownload for WindowsDownload for Linux

What Godot is checking

JSON is a class in Godot 4. parse_string() and stringify() are static; parse() is an instance method that returns an Error and keeps the result in the instance's data, with get_error_line() and get_error_message() when it fails.

JSON numbers come back as float, and object keys as String, whatever they looked like in the file.

More on this: Invalid type in static function 'from_angle' in type 'Vector2'. Cannot convert argument 1 from String to float in Godot 4

Reproduce it

A Godot 3 JSON parse, in a Godot 4 project.

GDScript
extends Node

func _ready():
	var data = JSON.parse('{"hp": 3}').result
	print(data)

What Godot 4.7.2 prints

Output
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

SCRIPT ERROR: Parse Error: Cannot call non-static function "parse()" on the class "JSON" directly. Make an instance instead.
   at: GDScript::reload (res://answers/how-to-parse-json-in-godot-4/repro.gd:4)
SCRIPT ERROR: Parse Error: Cannot get property from enum value.
   at: GDScript::reload (res://answers/how-to-parse-json-in-godot-4/repro.gd:4)
ERROR: Failed to load script "res://answers/how-to-parse-json-in-godot-4/repro.gd" with error "Parse error".
   at: load (modules/gdscript/gdscript_resource_format.cpp:46)

Fix it

parse_string() for the data, and a JSON instance when you need the error's line.

More on this: Invalid operands 'String' and 'int' in operator '+' in Godot 4

GDScript
extends Node

func _ready() -> void:
	var data = JSON.parse_string('{"hp": 3, "name": "Ada"}')
	print(data, " hp is ", type_string(typeof(data["hp"])))
	var json := JSON.new()
	var err := json.parse('{"hp": }')
	print(error_string(err), " at line ", json.get_error_line(), ": ", json.get_error_message())

What the fixed script prints

Output
Godot Engine v4.7.2.stable.mono.official.ed1daf0bf - https://godotengine.org

{ "hp": 3.0, "name": "Ada" } hp is float
Parse error at line 0: Expected value, got ''}''

Run this fix with your agent

Flockbay is the Godot editor with an AI agent built in. Paste this into Flockbay's chat, or into Claude Code or Codex connected to Flockbay over MCP: the agent finds the cause in your project, applies the fix, runs the game headless and reads Godot's output to check it.

More on this: How to get collisions after move_and_slide() in Godot 4

Prompt
How to parse JSON in Godot 4: JSON.parse_string() JSON.parse_string(text) returns the parsed Dictionary or Array, or null when the text is not valid JSON. Godot 3's JSON.parse(text).result fails to parse in Godot 4 with Cannot call non-static function "parse()" on the class "JSON" directly. Make an instance instead. Where this calls for a change in my Godot 4 project, make it, then run the game headless and check Godot's output for errors.

Verified on Godot 4.7.2

Both scripts on this page were run headless on Godot 4.7.2 (4.7.2.stable.mono.official.ed1daf0bf) on 18 October 2026, and the output above is what Godot printed, unedited.

Where the check lives in Godot's source: gdscript_analyzer.cpp line 3683, the message, JSON in the class reference.

Questions

How do I write JSON?
JSON.stringify(data), with an indent string as the second argument for readable output: JSON.stringify(data, "\t").
Why is my int a float after parsing?
JSON has one number type and Godot reads it as float. Convert with int() where you need an int.

Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot.

Download Flockbay free