cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
camer314
Helper I
Helper I

Why does JSON function not support arrays?

The JSON function does not seem to work at all with arrays:

 

Set(arrtest, JSON({arr: [1,2]}))

 

This should produce perfectly legal JSON however it insists on wanting to create key/value pairs, so instead it produces:

 

{"arr": [{"Value":1},{"Value":2}]}

 

Which is entirely incorrect. How can I get it to produce proper json for array data?

2 REPLIES 2
Pstork1
Dual Super User III
Dual Super User III

{arr: [1,2]} is a record of an object that contains a property that is an array.  That's exactly what the JSON() is translating it too.  For the JSON to work correctly the array has to be an array of Key/Value pairs.  Otherwise you will get the default key of "Value".  This is not an incorrect translation.  It is the proper translation of what you have submitted as JSON.

 

{arr: [1,2]} is not the same thing as [{arr:1}, {arr:2}].  Which would convert to what you want as JSON.



-------------------------------------------------------------------------
If I have answered your question, please mark your post as Solved.
If you like my response, please give it a Thumbs Up.

I still cant get this to format JSON the way I want. I am trying to call a custom connector that accepts a json object, that object is defined as:

 

    public class ProductInput
    {
        public Collection<int> Values { get; set; }
    }

 

If I create an instance of this in code and then serialize it I get what I expect, which is not something I can reproduce with the JSON formula:

 

var x = new ProductInput()
{
    Values = new System.Collections.ObjectModel.Collection<int>()
};

x.Values.Add(1);
x.Values.Add(2);

var s = JsonConvert.SerializeObject(x);

// "{\"Values\":[1,2]}"

 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (81,756)