Reading 1 value from the storage

Hi, sorry if the question answered before but I couldn’t find it.
I started using Nakama with Godot4 2 days a go and when I was trying the storage part I found that the code down is how i can read the storage, but I Cant understand it completely and wt if i want to get the value of 1 item in storage and save it in a variable wt will be the syntax, sorry for my bad English

{ar result : NakamaAPI.ApiStorageObjects = await client.read_storage_objects_async(session, [
    NakamaStorageObjectId.new("saves", "savegame", session.user_id)
])}

Hello @yuossf000,

If you’re only expecting one object the API should return a list with that single object, or empty if not found.

Have a look at:
Godot 4 - Heroic Labs Documentation and
Collections - Heroic Labs Documentation

Hope this clarifies.

Thank you for answering ,
I already read the document but when
my problem is when I read object from storage it will print everything about it like the key collection .
but what I want is to have only the vlaue for example
I have collection called player_ data and inside it I stored
level = 50
how I can read the level and store it into a variable
I was searching and as found I need to use
JSON.json.parse

var save_game = "{ \"progress\": 50 }"
	var my_stats = "{ \"skill\": 24 }"
	var can_read = 1
	var can_write = 1
	var version = ""
 	
	var acks : NakamaAPI.ApiStorageObjectAcks = await client.write_storage_objects_async(session, [
		NakamaWriteStorageObject.new("saves", "savegame", can_read, can_write, save_game, version),
		NakamaWriteStorageObject.new("stats", "skills", can_read, can_write, my_stats, version)
	])

like in this code how can i acces only the save_game = “{ “progress”: 50 }” from the storage
sorry for bad explination

Hi @yuossf000,
Godot already has suport to read json, as you can see here in the Godot Documentation. Also you can see at the end of the page a better way to serialize to json :slight_smile:

Baiscly when you read a json file, Godot transforms it into a dictionary. Here’s a small example:

var result : NakamaAPI.ApiStorageObjects = await client.read_storage_objects_async(session, [
    NakamaStorageObjectId.new("saves", "savegame", session.user_id)
])

if result.is_exception():
    print("An error occurred: %s" % result)
    return

## in this case the json is stored in the 'result' variable, let's try to read it

var json = JSON.new()
var result_dictionary =json.parse_string(JSON.stringify(result)) ## this transforms the object recieved into a string and then into a godot dictionary.

So now the object is in a Godot dictionary and you should easly be able to access its values. To see its structure just print(result_dictionary)

Let me know if that helps!

ty so much that’s helped