Description
Changelog
Reviews (0)

Copy the addons/jsonConverter/ directory into the addons/ directory of your Godot project. JsonConverter.gd declares the global class JSONConverter, so you can use it from any GDScript without creating an instance or configuring an autoload.

Convert a Resource to a JSON string:

var resource := preload("res://my_resource.tres")
var json := JSONConverter.stringify(resource)

# Optionally use spaces instead of the default tab indentation.
var formatted_json := JSONConverter.stringify(resource, "  ")

Restore a Resource from JSON:

var resource: Resource = JSONConverter.parse(json)
if resource == null:
    push_error("The JSON could not be converted to a Resource.")

The generic convert() method chooses the direction based on its argument:

var json: String = JSONConverter.convert(resource)
var restored_resource: Resource = JSONConverter.convert(json)

If you do not want to use the global class name, preload the script explicitly:

const JsonConverter := preload("res://addons/jsonConverter/JsonConverter.gd")

var json := JsonConverter.stringify(resource)
var restored_resource := JsonConverter.parse(json)

All public methods are static, so JSONConverter.new() is not required. The aliases resource_to_json() and json_to_resource() are also available if you prefer more explicit method names.

Changelog for version 1.4-alpha

No changelog provided for this version.

Reviews

Resource2JSON has no reviews yet.

Login to write a review.