question

dorime avatar image
dorime asked

Update part of a JSON

For example, in a game, I want to store a player's progress information.

This user data is stored first:

{
    "Worlds": [
        {
            "Id": 1,
            "Levels": [
                {
                    "Id": 1,
                    "Progress": 0
                },
                {
                    "Id": 2,
                    "Progress": 0
                }
            ]
        },
        {
            "Id": 2,
            "Levels": [
                {
                    "Id": 1,
                    "Progress": 0
                },
                {
                    "Id": 2,
                    "Progress": 0
                }
            ]
        }
    ]
}

When he progresses, I would like to send this information to update only the progress of World 1 - Level 1

{
    "Worlds": [
        {
            "Id": 1,
            "Levels": [
                {
                    "Id": 1,
                    "Progress": 500
                }
            ]
        }
    ]
}

Is it possible to achieve this result without having to get all the data from the server?

{
    "Worlds": [
        {
            "Id": 1,
            "Levels": [
                {
                    "Id": 1,
                    "Progress": 500  <-- value updated
                },
                {
                    "Id": 2,
                    "Progress": 0
                }
            ]
        },
        {
            "Id": 2,
            "Levels": [
                {
                    "Id": 1,
                    "Progress": 0
                },
                {
                    "Id": 2,
                    "Progress": 0
                }
            ]
        }
    ]
}
apisunity3ddata
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Gosen Gao avatar image
Gosen Gao answered

To clarify, the smallest unit to update User Data is one K/V pair. The value of one K/V pair can’t be updated in parts but can only be updated by overwriting. But as a workaround, you can get all the data first, and store it locally. Every time player progresses, you can just modify part of it then call update API with it.

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.