cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
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
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
News & Announcements

Community Blog

Stay up tp date on the latest blogs and activities in the community News & Announcements.

Power Apps Community Call

Power Apps Community Call- January

Mark your calendars and join us for the next Power Apps Community Call on January 20th, 8a PST

PP Bootcamp Carousel

Global Power Platform Bootcamp

Dive into the Power Platform stack with hands-on sessions and labs, virtually delivered to you by experts and community leaders.

secondImage

Power Platform Community Conference On Demand

Watch Nick Doelman's session from the 2020 Power Platform Community Conference on demand!

Top Solution Authors
Top Kudoed Authors
Users online (3,611)