# 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.

Source: https://flockbay.com/godot/how-to-parse-json-in-godot-4/ · Updated 2026-10-30

## 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.

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

## 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.

```
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](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.

Download Flockbay free: Flockbay's agent reads Godot's debugger output and fixes errors like this one in your project, on the official Godot. https://flockbay.com/download/

Related: [How to save and load a game in Godot 4: FileAccess](/godot/how-to-save-a-game-in-godot-4/), [How to get the current date and time in Godot 4: the Time singleton](/godot/how-to-get-the-current-date-and-time-in-godot-4/), [Invalid access to property or key '…' on a base object of type 'Dictionary' in Godot 4](/godot/invalid-access-to-property-or-key-on-dictionary/), [Invalid type in static function 'from_angle' in type 'Vector2'. Cannot convert argument 1 from String to float in Godot 4](/godot/invalid-type-in-static-function-cannot-convert-argument/), [Every verified Godot 4 answer](/godot/), [How do I connect Claude Code to Godot?](/docs/how-do-i-connect-claude-code-to-godot/)
