How work with an encrypted json file.

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By StarFox


In my project i have some data contained in the json file. I don’t want to let player can read it. So i need to encrypt the file, right? Right! It’s done with plugin for notepad++ NppCrypt. In godot i try to use file’s function “open_encrypted_with_pass”. And what you gonna think? It doesn’t work…

I do like that:

func _ready() -> void:
    var file : File =;
    var t = file.open_encrypted_with_pass("res://json/myjsonfile.json", file.READ, "secret");
    print(t) # And yeah, in my case it prints 7... it's try to abuse me or what?
    var json = file.get_as_text();
    pages = JSON.parse(json).result; #pages is Dictionary

Errors in tab “Errors” =):

  1. E 0:00:01.185 get_as_text: File must be opened before use.
    <C++ Error> Condition “!f” is true. Returned: String()
    <C++ Source> core/bind/core_bind.cpp:2087 @ get_as_text() @ _ready()

  2. E 0:00:01.195 parse: Error parsing JSON at line 0:
    <C++ Source> core/bind/core_bind.cpp:3284 @ parse() @ _ready()

Debuger print:
Trying to assign Nill to Dictionary (in short)

:bust_in_silhouette: Reply From: Calinou

Godot’s encrypted file support is not meant to interoperate with third-party encryption software. You can only load encrypted files that were saved by Godot.

1 Like