web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Copilot Studio / Handling poor formated...
Copilot Studio
Answered

Handling poor formated JSON answers from HTTP Request

(0) ShareShare
ReportReport
Posted on by 53
Hey all,
 
I've been trying to build a topic to handle a HTTP request. To do this I ask the user a series of questions which the user answers in natural language before being converted to IDs, used to build an query to an API. I've tested the query and got the answer back, but looking at the json structure I've found a problem: a field of the key:value pair in the json is actually build as an value:value. This makes it impossible to supply the agent with a model structure, since the value will change depending on the query build. Is there a way to fix this structure or process the json answer as a text/string? I've been trying alternatives but I'm stuck. Bellow is an example:
JSON Answer:
[
  {
    "id": "2289",
    "variavel": "INPC - Número-índice (base: dezembro de 1993 = 100)",
    "unidade": "Número-índice",
    "resultados": [
      {
        "classificacoes": [],
        "series": [
          {
            "localidade": {
              "id": "1",
              "nivel": {
                "id": "N1",
                "nome": "Brasil"
              },
              "nome": "Brasil"
            },
            "serie": {
              "200103": "1701.5800000000000"
            }
          }
        ]
      }
    ]
  }
]
Here the record serie should be built as an {"date": "200103", value: "1701.58000000"} pair, instead when adding this example to build an scheme, we get:
 
            serie:
                type:
                  kind: Record
                  properties:
                    200103: String
which yelds a null value for any other date. Any ideas how to handle/work around this? I've tried saving the answer as an string or any value types, which resulted in a type code error.
Categories:
I have the same question (0)
  • Michael E. Gernaey Profile Picture
    53,969 Moderator on at
     
    I would really love to see the query you are using because I would like to understand why the API is sending it back like this.
     
    I also do not understand when you say it yields null value for any other date, I would need more details on that.
     
    If it were simply a matter of it always doing date: whatever, then parsing
    serie
    wouldn't be difficult, but you would have to essentially update and or remove then re-add the properties correctly into the json before feeding it into parse json, which can be done in Power Automate, but I would need more details to solve the actual real problem of you getting that weird format back?
     
    Its odd that any API would send you back anything other than the correct format. Maybe I am missing something here as to the API you are calling, you are sure it gave you back the wrong format like that?
     
    can you look at the Agent/Flow or Tool so we can see the Outputs directly from the HTTP call please
  • Gsvc Profile Picture
    53 on at
     
     
     
     
    I would really love to see the query you are using because I would like to understand why the API is sending it back like this.
    The query is this one
    I also do not understand when you say it yields null value for any other date, I would need more details on that.
    What I mean is that when using the same schema for a different request we will have:
    ...
                  serie:
                    type:
                      kind: Record
                      properties:
                        200103: String
    ...
    The JSON parser will think 200103 it's a fixed key in the serie, and if i try to run the query for any other date it won't match, and the agent will assign an empty value. An example would be trying for march of 2002, for example.
     
    Its odd that any API would send you back anything other than the correct format. Maybe I am missing something here as to the API you are calling, you are sure it gave you back the wrong format like that?
    It's not that the JSON is wrong, but from a design perspective a variable date value should't be a key, but a value for a "date" key instead, and I can't tell copilot to just give me back the information as an text which I could feed as a prompt.
     
    wouldn't be difficult, but you would have to essentially update and or remove then re-add the properties correctly into the json before feeding it into parse json, which can be done in Power Automate
    sounds good! I did something similiar with python, but would prefer to keep the whole solution embedded in copilot studio or the microsoft ecosystem. I have no experience with power automate. It would work by creating a flow? I've tried sending the api response to an tool, but got error types, same when trying to save the response as a text instead of a json, and as a table type. 
  • Verified answer
    Gsvc Profile Picture
    53 on at
    I've managed to solve it saving the http request answer with the Any type, and then converting it to a JSON with the JSON power fx function. This resulted in a string variable which could be fed into the Prompt Tool to give an natural language answer. This way for our query :
     
    The answer was
    The value for the INPC for the index number variable in Brazil is 1701.58 in January, 2012.
  • Suggested answer
    Michael E. Gernaey Profile Picture
    53,969 Moderator on at
     
    Yes, using the Power FX is what you would have done in a direct Power Automate
     
    A Tool, An Agent Flow or Power Automate for Copilot are actually all just Flow... hidden :-).
     
    So essentially you did it a different way to convert it but logistically its still the same idea, since you need it in a different format.
     
    Whether you did it in Power FX in Power automate or Power FX in the Topic (or tool) its all potato, potato lol
     
    If my suggestions and details helped I would appreciate marking the answer.
     
    Cheers!!

    If these suggestions help resolve your issue, Please consider Marking the answer as such and also maybe a like.

    Thank you!
    Sincerely, Michael Gernaey

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Copilot Studio

#1
Valantis Profile Picture

Valantis 612

#2
chiaraalina Profile Picture

chiaraalina 170 Super User 2026 Season 1

#3
deepakmehta13a Profile Picture

deepakmehta13a 116

Last 30 days Overall leaderboard