'Json dynamic fields to struct issue [duplicate]

Every time I resolve one issue I get into another similar but different.

I need to convert into struts below JSON, but some parts are dynamic. and I am not very experienced with this conversions and I get very confused.

Below I have two fields that are different not static ( I was able with the help of this forum resolve a similar issue with one dynamic entry, but now I have two). the fields I called them "This string changes" so is less confusing.

[null,null,"hub:zWXKROOM","presence_state",{"74ce1906-af89-48a9-aec7-501369509000":{"metas":[{"context":{"embed":false,"mobile":false},"permissions":{"close_hub":false,"embed_hub":false,"fly":true,"join_hub":true,"kick_users":false,"mute_users":false,"pin_objects":false,"spawn_and_move_media":true,"spawn_camera":true,"spawn_drawing":false,"spawn_emoji":true,"update_hub":false,"update_hub_promotion":false,"update_roles":false},"phx_ref":"tGJf9IxredI=","phx_ref_prev":"zJ3pFzeYafM=","presence":"room","profile":{"avatarId":"3IADk9x","displayName":"real changeling"},"roles":{"creator":false,"owner":false,"signed_in":false}}]},"774e91d5-a324-47d7-ba75-edf9ed5bbe1a":{"metas":[{"context":{"embed":false,"mobile":false},"permissions":{"close_hub":false,"embed_hub":false,"fly":true,"join_hub":true,"kick_users":false,"mute_users":false,"pin_objects":false,"spawn_and_move_media":true,"spawn_camera":true,"spawn_drawing":false,"spawn_emoji":true,"update_hub":false,"update_hub_promotion":false,"update_roles":false},"phx_ref":"NnAT0YpIaUg=","phx_ref_prev":"tzv+xV6h0Rs=","presence":"room","profile":{"avatarId":"PcJ8Sxb","displayName":"GoBotWebSockets"},"roles":{"creator":false,"owner":false,"signed_in":false}}]},"9bd22f70-521a-49c2-9cb9-ac58dabfa1d6":{"metas":[{"context":{"embed":false,"mobile":false},"permissions":{"close_hub":false,"embed_hub":false,"fly":true,"join_hub":true,"kick_users":false,"mute_users":false,"pin_objects":false,"spawn_and_move_media":true,"spawn_camera":true,"spawn_drawing":false,"spawn_emoji":true,"update_hub":false,"update_hub_promotion":false,"update_roles":false},"phx_ref":"kPknFXlNkMo=","phx_ref_prev":"IA2Es263VdA=","presence":"room","profile":{"avatarId":"3IADk9x","displayName":"killab33z"},"roles":{"creator":false,"owner":false,"signed_in":false}}]},"f87b718a-c873-40a9-99db-91b4d0f7f4de":{"metas":[{"context":{"embed":false,"mobile":false},"permissions":{"close_hub":true,"embed_hub":true,"fly":true,"join_hub":true,"kick_users":true,"mute_users":true,"pin_objects":true,"spawn_and_move_media":true,"spawn_camera":true,"spawn_drawing":true,"spawn_emoji":true,"update_hub":true,"update_hub_promotion":false,"update_roles":true},"phx_ref":"XCCt44iesAo=","presence":"lobby","profile":{"avatarId":"https://s3.amazonaws.com/readyplayerbaker/avatars_baked/89e86e1a-43c7-4520-8f91-9a94ed42a722.glb","displayName":"ReK2"},"roles":{"creator":true,"owner":true,"signed_in":true}}]}}]

with a lot of help of someone here I was able to convert a very similar one but with two I cant seem to get it to work. I keep getting empty results..

the similar approach is Here

I have tried replicating with a field above and other similar things. I have look many blogs for this situation, no luck.

I also have try this tools, but is not really working because the tool does not know the details

edit: here is from json lint:

[
  null,
  null,
  "hub:zWXKROOM",
  "presence_state",
  {
    "74ce1906-af89-48a9-aec7-501369509000": {
      "metas": [
        {
          "context": {
            "embed": false,
            "mobile": false
          },
          "permissions": {
            "close_hub": false,
            "embed_hub": false,
            "fly": true,
            "join_hub": true,
            "kick_users": false,
            "mute_users": false,
            "pin_objects": false,
            "spawn_and_move_media": true,
            "spawn_camera": true,
            "spawn_drawing": false,
            "spawn_emoji": true,
            "update_hub": false,
            "update_hub_promotion": false,
            "update_roles": false
          },
          "phx_ref": "tGJf9IxredI=",
          "phx_ref_prev": "zJ3pFzeYafM=",
          "presence": "room",
          "profile": {
            "avatarId": "3IADk9x",
            "displayName": "real changeling"
          },
          "roles": {
            "creator": false,
            "owner": false,
            "signed_in": false
          }
        }
      ]
    },
    "774e91d5-a324-47d7-ba75-edf9ed5bbe1a": {
      "metas": [
        {
          "context": {
            "embed": false,
            "mobile": false
          },
          "permissions": {
            "close_hub": false,
            "embed_hub": false,
            "fly": true,
            "join_hub": true,
            "kick_users": false,
            "mute_users": false,
            "pin_objects": false,
            "spawn_and_move_media": true,
            "spawn_camera": true,
            "spawn_drawing": false,
            "spawn_emoji": true,
            "update_hub": false,
            "update_hub_promotion": false,
            "update_roles": false
          },
          "phx_ref": "NnAT0YpIaUg=",
          "phx_ref_prev": "tzv+xV6h0Rs=",
          "presence": "room",
          "profile": {
            "avatarId": "PcJ8Sxb",
            "displayName": "GoBotWebSockets"
          },
          "roles": {
            "creator": false,
            "owner": false,
            "signed_in": false
          }
        }
      ]
    },
    "9bd22f70-521a-49c2-9cb9-ac58dabfa1d6": {
      "metas": [
        {
          "context": {
            "embed": false,
            "mobile": false
          },
          "permissions": {
            "close_hub": false,
            "embed_hub": false,
            "fly": true,
            "join_hub": true,
            "kick_users": false,
            "mute_users": false,
            "pin_objects": false,
            "spawn_and_move_media": true,
            "spawn_camera": true,
            "spawn_drawing": false,
            "spawn_emoji": true,
            "update_hub": false,
            "update_hub_promotion": false,
            "update_roles": false
          },
          "phx_ref": "kPknFXlNkMo=",
          "phx_ref_prev": "IA2Es263VdA=",
          "presence": "room",
          "profile": {
            "avatarId": "3IADk9x",
            "displayName": "killab33z"
          },
          "roles": {
            "creator": false,
            "owner": false,
            "signed_in": false
          }
        }
      ]
    },
    "f87b718a-c873-40a9-99db-91b4d0f7f4de": {
      "metas": [
        {
          "context": {
            "embed": false,
            "mobile": false
          },
          "permissions": {
            "close_hub": true,
            "embed_hub": true,
            "fly": true,
            "join_hub": true,
            "kick_users": true,
            "mute_users": true,
            "pin_objects": true,
            "spawn_and_move_media": true,
            "spawn_camera": true,
            "spawn_drawing": true,
            "spawn_emoji": true,
            "update_hub": true,
            "update_hub_promotion": false,
            "update_roles": true
          },
          "phx_ref": "XCCt44iesAo=",
          "presence": "lobby",
          "profile": {
            "avatarId": "https://s3.amazonaws.com/readyplayerbaker/avatars_baked/89e86e1a-43c7-4520-8f91-9a94ed42a722.glb",
            "displayName": "ReK2"
          },
          "roles": {
            "creator": true,
            "owner": true,
            "signed_in": true
          }
        }
      ]
    }
  }
]

[edit2] I did a lot of multiple tries but still is not printing anything at all! is like there is no data but there is data... can someone please check my code and see what im I doing wrong? this last one I did step by step with a tutorial, still is not even showing any data, I wish it did so at least I know what to change.. https://gitlab.com/rek2/gohubsbot/-/blob/master/websocketsListen.go thanks



Solution 1:[1]

ok after a lot of debugging, reading, reading, hitting my head and stripping json to make it simples to post on json to go tools... I finally got it.. the main issue?

//the type needs to be a map itself
type PresenceState map[string]State

Also:

// even do I did try  this above I never called it the right way before so was giving up and moving on... but I have to use a pointer

for k, o := range *v {}

is working now. I am getting the keys and objets when there is a presence state at login or change so I can map id to usernames

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rek2