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

JSON format not correct

I was able to call my WCF service from a stream. I now have the following problem.
My WCF service returns a JSON that I believe is correctly formatted and in other applications that call it I have no problem as I can extract the result object from the response which contains only the Json.
When I call the service from my flow what I receive in output is not a clean Json but the body that contains the Json inside.
I guess this is why from Power apps when I try to run the flow.run () command it tells me that the JSON is incorrect.
How can I isolate the result from the Body? Below you can see the output of mi HTTP request
Thanks

 

 

 

  {
    "BANFN": "5000003823",
    "BNFPO": "00010",
    "TXZ01": "GIGASET A540 VOIP",
    "ERNAM": "RLEWIN",
    "MENGE": "       5.000",
    "EKGRP": "N16"
    }
]</visualizza_lista_rda_jsonResult><uid>fcedrini</uid><pwd>pascol</pwd></visualizza_lista_rda_jsonResponse></s:Body></s:Envelope>
1 ACCEPTED SOLUTION

Accepted Solutions

Unfortunately, there's no built in way to convert JSON to a collection.

Perhaps you could use one of the workarounds that are mentioned here?

https://powerusers.microsoft.com/t5/Building-Power-Apps/Parse-JSON-string-in-Power-APPS/td-p/381832

 

View solution in original post

6 REPLIES 6
timl
Super User
Super User

Hi @Citrix73 

With this example result from your WCF service, you can isolate the JSON content by searching for the positions of the { and } characters. You can then call the mid function to retrieve the content between these two characters.

https://docs.microsoft.com/en-gb/powerapps/maker/canvas-apps/functions/function-left-mid-right

You can then call the plaintext function to unencode the output.

Here are the formulas to store the input values in variables.

Set(varWsOutput,
"<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/""><s:Body><visualizza_lista_rda_jsonResponse xmlns=""http://...;
  {&#xD;
    ""BANFN"": ""5000003823"",&#xD;
    ""BNFPO"": ""00010"",&#xD;
    ""TXZ01"": ""GIGASET A540 VOIP"",&#xD;
    ""ERNAM"": ""RLEWIN"",&#xD;
    ""MENGE"": ""       5.000"",&#xD;
    ""EKGRP"": ""N16""&#xD;
    }&#xD;
]</visualizza_lista_rda_jsonResult><uid>fcedrini</uid><pwd>pascol</pwd></visualizza_lista_rda_jsonResponse></s:Body></s:Envelope>");

Set(varStart,
Find(
"{", varWsOutput));

Set(varEnd,
Find(
"}", varWsOutput))


The following formula will return the JSON content.

PlainText(Mid(varWsOutput,
    varStart, 
    (varEnd-varStart)+1)
)

timl_0-1603182813773.png

 

 

 

Thanks Timl,

excuse me but i'm novice on powerapps.

Where i have to insert these formulas?

I use a Flow to call the wcf service. It's scorrect? In image Below you can see my call.

I take this opportunity for ask you how can i dinamically set the parameters of request.

As you can see in attachment now i call the service copying in the body of request all the query parameters.

Thanks a lot

 

Citrix73_1-1603283292570.png

 

 

I think that i am near the solution.

with your help now i have isolated the clear json

With the formula that you suggest i have a variable vith the clear Json but if i try to populate a collection with this variable it seem not recognize the json but a single text as you can see in the secon screenshot where you can see the collection that i want to connect to my vertical gallery. How can i populate correctly the collection? Please

Citrix73_0-1603815302495.png

Citrix73_1-1603815592193.png

 

 

Unfortunately, there's no built in way to convert JSON to a collection.

Perhaps you could use one of the workarounds that are mentioned here?

https://powerusers.microsoft.com/t5/Building-Power-Apps/Parse-JSON-string-in-Power-APPS/td-p/381832

 

Your help has been invaluable.
I populated the collection although I had to make some corrections to your formula as using the mid function with start and end {} the resulting variable was only the first record of the Json. Therefore using [] instead the result is all the complete Json that you see below.
Now I have another problem using the workaround you suggested to load the collection from the Json and passing it this Json always returns me only the first record in the collection.
I have created a flow as described in workarond that you suggest me that parse this Json but the result is only first record.
Where is the problem? Below i attached also the screenshot of my flow to convert JSON to Collection
Thanks a lot

 

{
"BANFN": "5000003840",
"BNFPO": "00010",
"TXZ01": "BROTHER 2710 DN",
"ERNAM": "RLEWIN",
"MENGE": " 1.000",
"EKGRP": "N16"
},
{
"BANFN": "5000003843",
"BNFPO": "00010",
"TXZ01": "SWITCH 8P NETGEAR",
"ERNAM": "RLEWIN",
"MENGE": " 1.000",
"EKGRP": "N16"
},
{
"BANFN": "5000003843",
"BNFPO": "00020",
"TXZ01": "GIGASET A170",
"ERNAM": "RLEWIN",
"MENGE": " 1.000",
"EKGRP": "N16"
},
{
"BANFN": "5000003842",
"BNFPO": "00010",
"TXZ01": "SWITCH UNIEURO 5 P",
"ERNAM": "RLEWIN",
"MENGE": " 1.000",
"EKGRP": "N16"
}

 
 

 

 

 

 

 

 
 

 

Excuse me.

Resolved.

The Json schema was not correct

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

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