Create object from arrey

Options
Hey! I want to do the following:I need to get an Object with a key:value pair

I get a JSON response like this, and as I understand it, my array contains a variable. Correct, if not, I'm still a noob in this matter.[Снимок экрана 2021-12-24 в 1.35.42.png]I need this to be a pure variable with no square brackets. Based on what I saw in this instruction: https://docs.xano.com/working-with-data/functions/data-manipulation/objects 

These are the settings for creating Object I have now.
[Снимок экрана 2021-12-24 в 1.38.24.png][Снимок экрана 2021-12-24 в 1.38.29.png]
[Снимок экрана 2021-12-24 в 1.38.34.png]And this is the response I get
[Снимок экрана 2021-12-24 в 1.40.53.png]
What i'm doing wrong and how i can implement it? I want to get someting like this
[Снимок экрана 2021-12-24 в 1.44.57.png]
In my case it should be like
[
{
"key":"impression",
"value":"57005"
},

{
"key":"spend",
"value":"17309.45"
},

etc.
]

Comments

  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    Use dot notation to isolate the object

    So you'd create a variable that is

    variable_name.ad_accounts_insight

    Or if your variable is ad_accounts_insight and you know the index you could just do ad_accounts_insight.0 (array indexes start at 0 and increment)
  • Evgeny Sporykhin
    Options
     Thanks! I'll try it
  • Evgeny Sporykhin
    Options
    Hi  i start try to work with dot notation. But i still cant get it to work. But i deeply understanding how my response should be:

    I must have an Array that contains an Object with fields "Start Date" and "End date"  and  another Array with Object "Metrics" is contained and each metric stores 2 fields "Values" ​​- which indicates the name of the metric and "Value", which stores the value of the metric

    Example:
    ad_accounts_insight: {
    data: [
    {
    date_start = 2021-10-08
    date_end = 2021-10-08
    metrics:[
    {
      metric:impressions
      value:3489
    },
    {
      metric:reach
            value:3429
    },
    {
        metric:frequency
        value:1.017498
    }
    ]
    },
    date_start = 2021-10-09
    date_end = 2021-10-09
    metrics:[
    {
      metric:impressions
      value:3439
    },
    {
      metric:reach
            value:65429
    },
    {
        metric:frequency
        value:2.032498
    }
    ]

    Is it real? And if yes - can you show me or send tutorial which i should see for solving this task. It will be great if you can make it out on this particular example. Perhaps for some kind of payment
  • Evgeny Sporykhin
    Options
    UPDATE
    I use loop for each and get correct response. But, in my array i have 4 objects, but i get response only for first object

    It's my settings
    [Снимок экрана 2021-12-24 в 18.32.34.png]
    And this response
    [Снимок экрана 2021-12-24 в 18.38.30.png] 
    And question: how i can add other objects in this array?
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
     If the object is an array you should be able to use the merge filter - if it is not an array then you could use the push filter
  • Michael Udinski
    Michael Udinski Administrator

    ADMIN

    Options
    There's also the array functions like add to beginning of array or add to end of an array