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 Windows

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 '…' in type '…'. Cannot convert argument in Godot 4

Reproduce it

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

extends Node

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

What Godot 4.7.2 prints

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.

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

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 ''}''

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](https://github.com/godotengine/godot/blob/4.7.2-stable/modules/gdscript/gdscript_analyzer.cpp#L3683), [JSON in the class reference](https://github.com/godotengine/godot/blob/4.7.2-stable/doc/classes/JSON.xml).

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.