cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
MichelH
Level 8

JSON function using JSONFormat.IndentFour not working as suggested in documentation

I read the JSONFormat.IndentFour option should be able to format a json string, giving it proper indenting so it becomes readable.

 

The example I found here uses a label to display the formated json text.

It even shows a coloured formatted JSON output. (could it be real?)

 

When I try to do the same, I do not see this result unfortunately.

 

My plain JSON text, displayed in a label looks like this:

{"name":"c43187c3-3693-4ac9-844f-08dfefd8f09d","id":"/providers/Microsoft.Flow/....

After using the JSON function:

Set( OutPutTxt , JSON( MyJSONtxt ,JSONFormat.IndentFour ));

the output in the label looks like this:

"{\"name\":\"c43187c3-3693-4ac9-844f-08dfefd8f09d\",\"id\":\"/providers/Microsoft.Flow/....

 

Has anyone tried? Does anyone see where I go wrong here?

 

I've tried the same in an input field, and a rich text field.

I see the same results.

 

Thanks for any feedback.

21 REPLIES 21
Dual Super User
Dual Super User

Re: JSON function using JSONFormat.IndentFour not working as suggested in documentation

If you look at the example you will see that the collection used to feed the JSON has no quotes around the field names.  Try the following syntax instead of what you posted

ClearCollect(jsonTXT, {name:"c43187c3-3693-4ac9-844f-08dfefd8f09d",id:"/providers/Microsoft.Flow/"}); Set( OutPutTxt , JSON( jsonTXT ,JSONFormat.IndentFour ));


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

Re: JSON function using JSONFormat.IndentFour not working as suggested in documentation

Hi @Pstork1 ,

 

As you can see in the example I gave, the original json does not have any quotes around it.

 

In fact the quotes you see as well as the \" are added, when I use the JSON function. 

 

Michel

Dual Super User
Dual Super User

Re: JSON function using JSONFormat.IndentFour not working as suggested in documentation

I wasn't talking about quotes around the JSON itself.  I was talking about quotes around the field names, like "name" and "id".  JSON in Power Apps doesn't want the field names inside the JSON to be quoted.  You'll notice in my example they are not.



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

Re: JSON function using JSONFormat.IndentFour not working as suggested in documentation

Ah I see it now.

 

So the input is kind of restricted.

I'm getting my json from flow (power automate), and it is correct json AFAIK.

There is nothing wrong with quotes around the field names, in fact they are required when the name has a space in it.

I thought the JSON function would be able to handle that.  

My external json formatters are OK with that.

 

I guess I will need to figure out my own conversion then.

 

Thanks for your feedback.

 

It is good to know the limitations.

 

Michel

 

 

MichelH
Level 8

Re: JSON function using JSONFormat.IndentFour not working as suggested in documentation

@Pstork1 

 

Actually the example on the microsoft side also has these quotes. 

 

[{"Cities":[{"City":"London","Population":8615000}],"Country":"United Kingdom"},{"Cities":[{"City":"Berlin","Population":3562000},{"City":"Hamburg","Population":1760000},{"City":"Munich","Population":1494000}],"Country":"Germany"},{"Cities":[{"City":"Madrid","Population":3165000},{"City":"Barcelona","Population":1602000}],"Country":"Spain"}]

 

And there it doesn't seem to matter.

 

[
    {
        "Cities": [
            {
                "City": "London",
                "Population": 8615000
            }
        ],
        "Country": "United Kingdom"
    },
    {
        "Cities": [
            {
                "City": "Berlin",
                "Population": 3562000
            },
            {
                "City": "Hamburg",
                "Population": 1760000
            },
            {
                "City": "Munich",
                "Population": 1494000
            }
        ],
        "Country": "Germany"
    },
    {
        "Cities": [
            {
                "City": "Madrid",
                "Population": 3165000
            },
            {
                "City": "Barcelona",
                "Population": 1602000
            }
        ],
        "Country": "Spain"
    }
]

 

How did you become aware of this limitation?

 

Is this behaviour documented anywhere?

 

I feel it is more like a bug.

 

Michel

Dual Super User
Dual Super User

Re: JSON function using JSONFormat.IndentFour not working as suggested in documentation

That's not what I'm seeing on that page in the example.  Here's the text from the example

ClearCollect( CityPopulations,
    { City: "London",    Country: "United Kingdom", Population: 8615000 },
    { City: "Berlin",    Country: "Germany",        Population: 3562000 },
    { City: "Madrid",    Country: "Spain",          Population: 3165000 },
    { City: "Hamburg",   Country: "Germany",        Population: 1760000 },
    { City: "Barcelona", Country: "Spain",          Population: 1602000 },
    { City: "Munich",    Country: "Germany",        Population: 1494000 }
);
ClearCollect( CitiesByCountry, GroupBy( CityPopulations, "Country", "Cities" ) )

Notice that City, Country, and Population are NOT surrounded by quotes. 



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

Re: JSON function using JSONFormat.IndentFour not working as suggested in documentation

Hi @Pstork1,

 

Indeed, bad reading on my part.

 

I tested your suggestion of course,

{name:"c43187c3-3693-4ac9-844f-08dfefd8f09d",id:"/providers/Microsoft.Flow/",test:{p:"p", q:"q", r:"r"}}

and see that then, it does give the formatted output as expected.

{
    "id": "/providers/Microsoft.Flow/",
    "name": "c43187c3-3693-4ac9-844f-08dfefd8f09d",
    "test": {
        "p": "p",
        "q": "q",
        "r": "r"
    }
}

 

But now of course I need a way to filter the quotes around the field names in the json I get from flow.

 

Bit of a catch22, and quite strange that it generates a json format, it won't accept itself. 

 

Dual Super User
Dual Super User

Re: JSON function using JSONFormat.IndentFour not working as suggested in documentation

What is actually producing the JSON?  If the JSON is coming from Flow try just loading it directly into a collection.  That's what I normally do and then the collection works like the one manually created in the article.  For example I've got a Flow that runs a SQL stored procedure.  The schema of the returned JSON looks like this:

{
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "Title": {
                "type": "string"
            }, ...

But using a ClearCollect I can load that directly into a collection.

ClearCollect(SqlData,SqlGetActive.Run(DatePicker1.SelectedDate))

I think the problem you are running into is that you are trying to load the JSON from a string, not from a collection (ARRAY).



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

Re: JSON function using JSONFormat.IndentFour not working as suggested in documentation

Hi @Pstork1,

 

I'm loading a variable directly from a Flow.Run

Set(FlowRes, FlowAction2.Run("Get",Gallery1.Selected.Id).res );

 The 'res' is the body output from the 'Get Flow' connector.

 

So what I get back cannot go into an array first.  🙂  It is not an array.

 

Michel

 

 

 

Helpful resources

Announcements
Better Together’ Contest Finalists Announced!

'Better Together’ Contest Finalists Announced!

Congrats to the finalists of our ‘Better Together’-themed T-shirt design contest! Click for the top entries.

thirdimage

Power Apps Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Join THE global Microsoft Power Platform event series

Attend for two days of expert-led learning and innovation on topics like AI and Analytics, powered by Dynamic Communities

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

thirdimage

Microsoft Business Applications Virtual Launch

Join us for the Microsoft Business Applications Virtual Launch Event on Thursday, April 2, 2020, at 8:00 AM PST.

thirdimage

Community Summit North America

Innovate, Collaborate, Grow - The top training and networking event across the globe for Microsoft Business Applications

Top Solution Authors
Top Kudoed Authors
Users online (9,475)