Questions hidden by 'relevance' logic does not appear in some json results

I made a form that asks a different set of questions for each type of respondent. When pulling json data through the v2 api, only the set of questions asked from the respondent appear in the respective submission.

For example: I asked respondent 1 to answer questions 1,2,3,4 and I asked repondent 2 to answer questions 1,2,5,6. The json result for respondent 1 would only be 1,2,3,4 and for respondent 2 1,2,5,6 instead of the assumed 1,2,3,4,5,6. AFAIK the questions were actually in the form only that they are hidden based on some logic.

This is a big problem for me since I am trying to pull data into google sheets using google scripts, list and dataframe operations/syntax from R is non-existent in the js based google scripts.

I hope someone might at least provide some workaround for me, I am thinking of looping each item for each submission but I dont know if it will order the column names the same way it is ordered in the json results.

PS Also column orders in v2 json api is not the same as the order of questions in the xls file.
For example you asked questions (1,2,3,4,5,6) and (7,8,9,10,11,12) in order and in 2 groups the json response at least when called in google sheets will rearrange the questions in alphabetical order (not sure if this is the particular order)

I solved the problem by using TJ Crowders solution in:

But this does not solve the problem in general since this only applies if you are using js/google scripts.

The json returns columns in a weird order, completely different from the order that the questions are asked. I am thinking of modifying the above solution to reorder the columns