Factory objects in JSON

Hello!

I create objects through a factory and they have properties, these properties are a hash.

local properties = {card_hash = hash(card_string), suit = hash(card.suit), rank = card.rank}

When I create these objects I save them to a table and the table looks like:

hash: [/instance1] = { --[[0000026B9BDEE5F0]]
    properties = { --[[0000026B9BDEDDA0]]
      suit = hash: [s],
      card_hash = hash: [2s],
      rank = 2
    },
    position = vmath.vector3(130, 35, 0)
  },
  hash: [/instance2] = { --[[0000026B9BDEEF50]]
    properties = { --[[0000026B9BDEE740]]
      suit = hash: [h],
      card_hash = hash: [3h],
      rank = 3
    },
    position = vmath.vector3(200, 35, 0)
  },

How can I convert data from a table to JSON?
Because if I just do json.encode(my_table) then I get an error: Cannot serialise userdata: table key must be a number or string

I tried to figure it out with this extension, but I still didn’t understand how to work with the hash.

Thanks!

As you saw, it is not possible to encode user data such as a hash to json. The question is what you intend to do with the json data? Can you change from a map with key values to a list of values?

I’m not sure I can get to the list of values. At least I don’t know how to do it. I’m making a game for Yandex, SDK needs to send data to the server, but they only accept json, most likely I need to revise my code and get rid of hashes altogether. When spawning objects through a factory, I will add the created object to the table, and the table already looks like I described above. Can you recommend any optimal solution?

I can do something with the object data itself with rank, suit and position, but what about the fact that the factory object is already of type hash? hash: [/instance2] and so on

And what will happen with the data on the server? Do you need to parse it on the server?