Mixpanel Community Icon

Workaround for Manipulating Arrays of Objects in Custom Properties

·
·

Hey all, is there a way (or a workaround) to manipulate an array of objects within custom properties? It sounds like I can only handle arrays of basic types (strings, booleans, etc.)

  • Avatar of Christopher C.
    Christopher C.
    ·
    ·

    Yeah, this is a bit more complex, but it is possible. Depending on what you're after, it is sometimes easier to use indexes, eg stuff like:

    LET(X, 3,
    NUMBER(IFS(
    @"""{"joinPropertyType":"list","label":"Balances","propertyDefaultType":"object","resourceType":"event","type":"object","value":"balances"}"""@[0]["asset_id"] == X, @"""{"joinPropertyType":"list","label":"Balances","propertyDefaultType":"object","resourceType":"event","type":"object","value":"balances"}"""@[0]["amount"],
    @"""{"joinPropertyType":"list","label":"Balances","propertyDefaultType":"object","resourceType":"event","type":"object","value":"balances"}"""@[1]["asset_id"] == X, @"""{"joinPropertyType":"list","label":"Balances","propertyDefaultType":"object","resourceType":"event","type":"object","value":"balances"}"""@[1]["amount"],
    ...
    )
    )
  • Avatar of Christopher C.
    Christopher C.
    ·
    ·

    which gives this, where we basically iterate through the array to check if each item matches the asset ID we're after, and if it matches, we return the amount property for that item. You can get away with casting your array property as a string and using REGEX too, but it is important to keep in mind that casting it as a string truncates the string at a certain point, so you need to ensure that your largest objects aren't larger than this, or the regex won't be reliable.

  • Avatar of Frédéric M.
    Frédéric M.
    ·
    ·