cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Help with parsing json and converting to array

Need help parsing this JSON - What I want to do is write a Compose that will output every 'answer' under subquestions (can be found under root->data->survey_data->"19"->subquestions->(number)->answer. I've been able to parse it and convert the data to an array as variable DataArray with array(body('Parse_JSON')?['data']) but that just gives me everything under 'data'. I want everything under 'subquestions'. But when I substitute 'subquestions' for 'data' it just returns null. Schema is below. I'm a total noob at this so please let me know if I can further clarify.

 

 

{
    "type": "object",
    "properties": {
        "result_ok": {
            "type": "boolean"
        },
        "total_count": {
            "type": "integer"
        },
        "page": {
            "type": "integer"
        },
        "total_pages": {
            "type": "integer"
        },
        "results_per_page": {
            "type": "integer"
        },
        "data": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "id": {
                        "type": "string"
                    },
                    "contact_id": {
                        "type": "string"
                    },
                    "status": {
                        "type": "string"
                    },
                    "is_test_data": {
                        "type": "string"
                    },
                    "date_submitted": {
                        "type": "string"
                    },
                    "session_id": {
                        "type": "string"
                    },
                    "language": {
                        "type": "string"
                    },
                    "date_started": {
                        "type": "string"
                    },
                    "link_id": {
                        "type": "string"
                    },
                    "url_variables": {
                        "type": "array"
                    },
                    "ip_address": {
                        "type": "string"
                    },
                    "referer": {
                        "type": "string"
                    },
                    "user_agent": {
                        "type": "string"
                    },
                    "response_time": {
                        "type": "integer"
                    },
                    "longitude": {
                        "type": "string"
                    },
                    "latitude": {
                        "type": "string"
                    },
                    "country": {
                        "type": "string"
                    },
                    "city": {
                        "type": "string"
                    },
                    "region": {
                        "type": "string"
                    },
                    "postal": {
                        "type": "string"
                    },
                    "dma": {
                        "type": "string"
                    },
                    "survey_data": {
                        "type": "object",
                        "properties": {
                            "ParentQuestionID": {
                                "type": "object",
                                "properties": {
                                    "id": {
                                        "type": "integer"
                                    },
                                    "type": {
                                        "type": "string"
                                    },
                                    "question": {
                                        "type": "string"
                                    },
                                    "subquestions": {
                                        "type": "object",
                                        "properties": {
                                            "SubQuestions": {
                                                "type": "object",
                                                "properties": {
                                                    "subquestionid": {
                                                        "type": "integer"
                                                    },
                                                    "question": {
                                                        "type": "string"
                                                    },
                                                    "type": {
                                                        "type": "string"
                                                    },
                                                    "parent": {
                                                        "type": "integer"
                                                    },
                                                    "answer": {
                                                        "type": "string"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "section_id": {
                                        "type": "integer"
                                    },
                                    "shown": {
                                        "type": "boolean"
                                    }
                                }
                            }
                        }
                    }
                },
                "required": [
                    "id",
                    "contact_id",
                    "status",
                    "is_test_data",
                    "date_submitted",
                    "session_id",
                    "language",
                    "date_started",
                    "link_id",
                    "url_variables",
                    "ip_address",
                    "referer",
                    "user_agent",
                    "response_time",
                    "longitude",
                    "latitude",
                    "country",
                    "city",
                    "region",
                    "postal",
                    "dma",
                    "survey_data"
                ]
            }
        }
    }
}

 

 

3 REPLIES 3
ChristianAbata
Super User
Super User

hi @Anonymous  do you try using parse json? did you use that action before?



Did I answer your question? Please consider to Mark
my post as a solution! to guide others :winking_face:

Proud to be a Flownaut!


If you want you can follow me at www.christianabata.com Quieres contenido en español? Síguenos en Power Automate LA
Anonymous
Not applicable

@ChristianAbata  I did use parseJSON before (see attached screenshot). And then I put it into a variable DataArray(array type)  using this

array(body('Parse_JSON')?['data'])
 
And this will spit out everything in then json under 'data' as an array. But when I try to put subquestions in where 'data' is it comes back null.
 
data1.PNG
SCTdan
Continued Contributor
Continued Contributor

You have to string them together I believe, so array(body('Parse_JSON')?['data']?['Survey_data']?['Parentquestionid']?['Subquestions'] ... and so on

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

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

Community Calls Conversations

Community Calls Conversations

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

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

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