为什么我的递归函数无法正确遍历JSON?

时间:2018-12-23 00:24:53

标签: javascript json

最近编辑为更简短

这可能是一个遥不可及的问题,但是我需要有关我创建的递归函数的帮助。它没有让我从JSON获得所需的值。基本上,我想获取具有“标准”或“块”的“类型”的所有“流”对象ID。这些对象可以嵌套在父“ Flow”对象下的多个“ Flow”对象中,这就是为什么我需要使用递归方法搜索所有对象的原因。我创建了一个Codepen,以便您可以看到我在这里得到的结果:

https://codepen.io/anon/pen/YdVyYG?editors=1012

该函数位于底部,称为“ GroupRecursion”,我将JSON“ Payload”作为参数传递。

我在名为ArrayOfBlockIDs的数组中仅获得约3个ID(字符串),我应该恰好获得4个字符串,因为有多少个对象具有“ Type” =“ Standard”或“ Block”。感谢您的宝贵时间,如果不是在这里,请告诉我。

var Payload = {
    "Type": "Root",
    "FlowID": "FL_1",
    "Flow": [
      {
        "Type": "Group",
        "FlowID": "FL_27",
        "Description": "Pass 1",
        "Flow": [
          {
            "Type": "EmbeddedData",
            "FlowID": "FL_7",
            "EmbeddedData": [
              {
                "Description": "JSON",
                "Type": "Recipient",
                "Field": "JSON",
                "VariableType": "String",
                "DataVisibility": [],
                "AnalyzeText": false
              },
              {
                "Description": "DisplayLogicFrom",
                "Type": "Recipient",
                "Field": "DisplayLogicFrom",
                "VariableType": "String",
                "DataVisibility": [],
                "AnalyzeText": false
              },
              {
                "Description": "DisplayLogicAt",
                "Type": "Recipient",
                "Field": "DisplayLogicAt",
                "VariableType": "String",
                "DataVisibility": [],
                "AnalyzeText": false
              }
            ]
          },
          {
            "Type": "Branch",
            "FlowID": "FL_54",
            "Description": "New Branch",
            "BranchLogic": {
              "0": {
                "0": {
                  "LogicType": "EmbeddedField",
                  "LeftOperand": "APITest",
                  "Operator": "EqualTo",
                  "RightOperand": "True",
                  "_HiddenExpression": false,
                  "Type": "Expression",
                  "Description": "<span class=\"ConjDesc\">If</span>  <span class=\"LeftOpDesc\">APITest</span> <span class=\"OpDesc\">Is Equal to</span> <span class=\"RightOpDesc\"> True </span>"
                },
                "Type": "If"
              },
              "Type": "BooleanExpression"
            },
            "Flow": [
              {
                "Type": "Standard",
                "ID": "BL_4NL909leoyn5KBf",
                "FlowID": "FL_51"
              },
              {
                "Type": "Standard",
                "ID": "BL_bBGbASH2RnPCskt",
                "FlowID": "FL_59"
              },
              {
                "Type": "WebService",
                "FlowID": "FL_50",
                "URL": "https://co1.qualtrics.com/API/v3/surveys",
                "Method": "POST",
                "RequestParams": [],
                "EditBodyParams": [
                  {
                    "key": "file",
                    "value": "${e://Field/TEST}"
                  },
                  {
                    "key": "name",
                    "value": "new survey"
                  }
                ],
                "Body": [
                  {
                    "key": "file",
                    "value": "${e://Field/TEST}"
                  },
                  {
                    "key": "name",
                    "value": "new survey"
                  }
                ],
                "ContentType": "application/x-www-form-urlencoded",
                "Headers": [
                  {
                    "key": "x-api-token",
                    "value": "h69TKYgxu46SMEXzcKkeRUXovq2jALTpHDhPUGLq"
                  }
                ],
                "ResponseMap": [
                  {
                    "key": "meta.requestId",
                    "value": "meta.requestId"
                  },
                  {
                    "key": "meta.error.errorCode",
                    "value": "meta.error.errorCode"
                  },
                  {
                    "key": "meta.error.errorMessage",
                    "value": "meta.error.errorMessage"
                  },
                  {
                    "key": "meta.httpStatus",
                    "value": "meta.httpStatus"
                  }
                ],
                "FireAndForget": false,
                "SchemaVersion": 0,
                "StringifyValues": true
              },
              {
                "Type": "Standard",
                "ID": "BL_4Yhl7MpygFG9Z6B",
                "FlowID": "FL_53"
              }
            ]
          },
          {
            "Type": "Standard",
            "ID": "BL_0GHahOV7Hb9l141",
            "FlowID": "FL_3"
          },
          {
            "Type": "Branch",
            "FlowID": "FL_5",
            "Description": "New Branch",
            "BranchLogic": {
              "0": {
                "0": {
                  "LogicType": "Question",
                  "QuestionID": "QID4",
                  "QuestionIsInLoop": "no",
                  "ChoiceLocator": "q://QID4/SelectableChoice/1",
                  "Operator": "Selected",
                  "QuestionIDFromLocator": "QID4",
                  "LeftOperand": "q://QID4/SelectableChoice/1",
                  "Type": "Expression",
                  "Description": "<span class=\"ConjDesc\">If</span> <span class=\"QuestionDesc\">What would you like to do?</span> <span class=\"LeftOpDesc\">Check if there is custom validation/Force Response on my survey and on what questions</span> <span class=\"OpDesc\">Is Selected</span> "
                },
                "Type": "If"
              },
              "Type": "BooleanExpression"
            },
            "Flow": [
              {
                "Type": "Block",
                "ID": "BL_3n1Vmp4FL6cZZuR",
                "FlowID": "FL_2"
              },
              {
                "Type": "EndSurvey",
                "FlowID": "FL_11"
              }
            ]
          },
          {
            "Type": "Branch",
            "FlowID": "FL_56",
            "Description": "New Branch",
            "BranchLogic": {
              "0": {
                "0": {
                  "LogicType": "Question",
                  "QuestionID": "QID4",
                  "QuestionIsInLoop": "no",
                  "ChoiceLocator": "q://QID4/SelectableChoice/6",
                  "Operator": "Selected",
                  "QuestionIDFromLocator": "QID4",
                  "LeftOperand": "q://QID4/SelectableChoice/6",
                  "Type": "Expression",
                  "Description": "<span class=\"ConjDesc\">If</span> <span class=\"QuestionDesc\">What would you like to do?</span> <span class=\"LeftOpDesc\">Re-Number the questions to be in order but add \"TEXT\" to descriptive text questions.</span> <span class=\"OpDesc\">Is Selected</span> "
                },
                "Type": "If"
              },
              "Type": "BooleanExpression"
            },
            "Flow": [
              {
                "Type": "Standard",
                "ID": "BL_9ESRPcpuMl5TNcx",
                "FlowID": "FL_60"
              },
              {
                "ID": "BL_cACgbdijKOAtRo9",
                "Type": "Standard",
                "FlowID": "FL_61"
              },
              {
                "Type": "Standard",
                "ID": "BL_0SuWoa7K2CkYFsV",
                "FlowID": "FL_55"
              }
            ]
          },
          {
            "Type": "Branch",
            "FlowID": "FL_58",
            "Description": "New Branch",
            "BranchLogic": {
              "0": {
                "0": {
                  "LogicType": "Question",
                  "QuestionID": "QID4",
                  "QuestionIsInLoop": "no",
                  "ChoiceLocator": "q://QID4/SelectableChoice/6",
                  "Operator": "NotSelected",
                  "QuestionIDFromLocator": "QID4",
                  "LeftOperand": "q://QID4/SelectableChoice/6",
                  "Type": "Expression",
                  "Description": "<span class=\"ConjDesc\">If</span> <span class=\"QuestionDesc\">What would you like to do?</span> <span class=\"LeftOpDesc\">Re-Number the questions to be in order but add \"TEXT\" to descriptive text questions.</span> <span class=\"OpDesc\">Is Not Selected</span> "
                },
                "Type": "If"
              },
              "Type": "BooleanExpression"
            },
            "Flow": [
              {
                "Type": "Standard",
                "ID": "BL_2tA1Ilad6iCEEu1",
                "FlowID": "FL_13"
              },
              {
                "Type": "EmbeddedData",
                "FlowID": "FL_14",
                "EmbeddedData": [
                  {
                    "Description": "APIToken",
                    "Type": "Custom",
                    "Field": "APIToken",
                    "VariableType": "String",
                    "DataVisibility": [],
                    "AnalyzeText": false,
                    "Value": "${q://QID18/ChoiceTextEntryValue/2}"
                  },
                  {
                    "Description": "Datacenter",
                    "Type": "Custom",
                    "Field": "Datacenter",
                    "VariableType": "String",
                    "DataVisibility": [],
                    "AnalyzeText": false,
                    "Value": "${q://QID18/ChoiceTextEntryValue/1}"
                  }
                ]
              },
              {
                "Type": "Standard",
                "ID": "BL_0r1ZjeAhMBEBhdz",
                "FlowID": "FL_4"
              },
              {
                "Type": "Branch",
                "FlowID": "FL_21",
                "Description": "New Branch",
                "BranchLogic": {
                  "0": {
                    "0": {
                      "LogicType": "Question",
                      "QuestionID": "QID17",
                      "QuestionIsInLoop": "no",
                      "ChoiceLocator": "q://QID17/SelectableChoice/4",
                      "Operator": "Selected",
                      "QuestionIDFromLocator": "QID17",
                      "LeftOperand": "q://QID17/SelectableChoice/4",
                      "Type": "Expression",
                      "Description": "<span class=\"ConjDesc\">If</span> <span class=\"QuestionDesc\">What type of questions will you be using?</span> <span class=\"LeftOpDesc\">matrix choice to multiple choice question</span> <span class=\"OpDesc\">Is Selected</span> "
                    },
                    "Type": "If"
                  },
                  "Type": "BooleanExpression"
                },
                "Flow": [
                  {
                    "Type": "Standard",
                    "ID": "BL_6ilSpb6iiCzWvtz",
                    "FlowID": "FL_20"
                  },
                  {
                    "Type": "Standard",
                    "ID": "BL_a4faBNVnTi19wLr",
                    "FlowID": "FL_23"
                  },
                  {
                    "Type": "EmbeddedData",
                    "FlowID": "FL_25",
                    "EmbeddedData": [
                      {
                        "Description": "Conjunction",
                        "Type": "Custom",
                        "Field": "Conjunction",
                        "VariableType": "String",
                        "DataVisibility": [],
                        "AnalyzeText": false,
                        "Value": "${q://QID32/ChoiceGroup/SelectedChoices}"
                      }
                    ]
                  },
                  {
                    "Type": "EmbeddedData",
                    "FlowID": "FL_26",
                    "EmbeddedData": [
                      {
                        "Description": "Operator",
                        "Type": "Custom",
                        "Field": "Operator",
                        "VariableType": "String",
                        "DataVisibility": [],
                        "AnalyzeText": false,
                        "Value": "${q://QID29/ChoiceGroup/SelectedChoices}"
                      }
                    ]
                  },
                  {
                    "Type": "Standard",
                    "ID": "BL_2lVBP4EOiOwT0Kp",
                    "FlowID": "FL_24"
                  }
                ]
              },
              {
                "Type": "Branch",
                "FlowID": "FL_6",
                "Description": "New Branch",
                "BranchLogic": {
                  "0": {
                    "0": {
                      "LogicType": "Question",
                      "QuestionID": "QID17",
                      "QuestionIsInLoop": "no",
                      "ChoiceLocator": "q://QID17/SelectableChoice/1",
                      "Operator": "Selected",
                      "QuestionIDFromLocator": "QID17",
                      "LeftOperand": "q://QID17/SelectableChoice/1",
                      "Type": "Expression",
                      "Description": "<span class=\"ConjDesc\">If</span> <span class=\"QuestionDesc\">What type of questions will you be using?</span> <span class=\"LeftOpDesc\">multiple choice to multiple choice</span> <span class=\"OpDesc\">Is Selected</span> "
                    },
                    "Type": "If"
                  },
                  "Type": "BooleanExpression"
                },
                "Flow": [
                  {
                    "Type": "EmbeddedData",
                    "FlowID": "FL_10",
                    "EmbeddedData": [
                      {
                        "Description": "Operator",
                        "Type": "Custom",
                        "Field": "Operator",
                        "VariableType": "String",
                        "DataVisibility": [],
                        "AnalyzeText": false,
                        "Value": "${q://QID13/ChoiceGroup/SelectedChoices}"
                      }
                    ]
                  },
                  {
                    "Type": "Standard",
                    "ID": "BL_4IMpxjrEATyLuqV",
                    "FlowID": "FL_19"
                  },
                  {
                    "Type": "Standard",
                    "ID": "BL_bBjaPeuYnHFtBBP",
                    "FlowID": "FL_9"
                  }
                ]
              }
            ]
          },
          {
            "Type": "Standard",
            "ID": "BL_eD0WiECJYD2l0nr",
            "FlowID": "FL_28"
          }
        ]
      },
      {
        "Type": "Standard",
        "ID": "BL_1Mk6LuLiukBnCU5",
        "FlowID": "FL_17"
      },
      {
        "Type": "EndSurvey",
        "FlowID": "FL_16"
      },
      {
        "Type": "WebService",
        "FlowID": "FL_15",
        "URL": "https://co1.qualtrics.com/API/v:version/surveys",
        "Method": "PUT",
        "RequestParams": [],
        "EditBodyParams": [
          {
            "key": "QuestionText",
            "value": "Hello"
          },
          {
            "key": "DataExportTag",
            "value": "Q2"
          },
          {
            "key": "QuestionType",
            "value": "MC"
          },
          {
            "key": "Selector",
            "value": "SAVR"
          },
          {
            "key": "SubSelector",
            "value": "TX"
          },
          {
            "key": "Configuration",
            "value": "{\"QuestionDescriptionOption\":\"UseText\"}",
            "parameterType": "JSON"
          },
          {
            "key": "QuestionDescription",
            "value": "Hello?"
          },
          {
            "key": "Choices",
            "value": "{\"Choices\": {\n          \"1\": {\n            \"Display\": \"Statement 1\"\n          },\n          \"2\": {\n            \"Display\": \"Statement 2\"\n          },\n          \"3\": {\n            \"Display\": \"Statement 3\"\n          }\n        }}",
            "parameterType": "JSON"
          },
          {
            "key": "Language",
            "value": "[]",
            "parameterType": "JSON"
          },
          {
            "key": "Validation",
            "value": "{\"Settings\": {\n            \"ForceResponse\": \"OFF\",\n            \"ForceResponseType\": \"ON\",\n            \"Type\": \"None\"\n          }}",
            "parameterType": "JSON"
          }
        ],
        "Body": {
          "QuestionText": "Hello",
          "DataExportTag": "Q2",
          "QuestionType": "MC",
          "Selector": "SAVR",
          "SubSelector": "TX",
          "Configuration": {
            "QuestionDescriptionOption": "UseText"
          },
          "QuestionDescription": "Hello?",
          "Choices": {
            "Choices": {
              "1": {
                "Display": "Statement 1"
              },
              "2": {
                "Display": "Statement 2"
              },
              "3": {
                "Display": "Statement 3"
              }
            }
          },
          "Language": [],
          "Validation": {
            "Settings": {
              "ForceResponse": "OFF",
              "ForceResponseType": "ON",
              "Type": "None"
            }
          }
        },
        "ContentType": "application/json",
        "Headers": [
          {
            "key": "x-api-token",
            "value": "h69TKYgxu46SMEXzcKkeRUXovq2jALTpHDhPUGLq"
          }
        ],
        "ResponseMap": [],
        "FireAndForget": false,
        "SchemaVersion": 0,
        "StringifyValues": true
      }
    ],
    "Properties": {
      "Count": 61,
      "RemovedFieldsets": []
    }
  }

    var ArrayOfBlockIDs = []
    var RecursionCount = 0;
    function GroupRecursion(item){

        for(i=0;i<item.Flow.length;i++){


            if(item.Flow[i].Type=="Standard" && ArrayOfBlockIDs.includes(item.Flow[i].ID)==false || item.Flow[i].Type=="Block" && ArrayOfBlockIDs.includes(item.Flow[i].ID)==false){
                    ArrayOfBlockIDs.push(item.Flow[i].ID)

            }

            if(item.Flow[i].Type=="Group" || item.Flow[i].Type=="Branch"){

                GroupRecursion(item.Flow[i])


            } 



        }


        console.log(ArrayOfBlockIDs)
    }

GroupRecursion(Payload);

//

1 个答案:

答案 0 :(得分:2)

您的代码似乎比所需的要复杂一些。我认为一个更简单的递归函数将找到所有这些。这只是一个函数,它需要一个数组来查找所需类型的每个项目,然后将子Flow数组通过该函数传递回去:

var Payload = {"Type": "Root","FlowID": "FL_1","Flow": [{"Type": "Group","FlowID": "FL_27","Description": "Pass 1","Flow": [{"Type": "EmbeddedData","FlowID": "FL_7","EmbeddedData": [{"Description": "JSON","Type": "Recipient","Field": "JSON","VariableType": "String","DataVisibility": [],"AnalyzeText": false},{"Description": "DisplayLogicFrom","Type": "Recipient","Field": "DisplayLogicFrom","VariableType": "String","DataVisibility": [],"AnalyzeText": false},{"Description": "DisplayLogicAt","Type": "Recipient","Field": "DisplayLogicAt","VariableType": "String","DataVisibility": [],"AnalyzeText": false}]},{"Type": "Branch","FlowID": "FL_54","Description": "New Branch","BranchLogic": {"0": {"0": {"LogicType": "EmbeddedField","LeftOperand": "APITest","Operator": "EqualTo","RightOperand": "True","_HiddenExpression": false,"Type": "Expression","Description": "<span class=\"ConjDesc\">If</span>  <span class=\"LeftOpDesc\">APITest</span> <span class=\"OpDesc\">Is Equal to</span> <span class=\"RightOpDesc\"> True </span>"},"Type": "If"},"Type": "BooleanExpression"},"Flow": [{"Type": "Standard","ID": "BL_4NL909leoyn5KBf","FlowID": "FL_51"},{"Type": "Standard","ID": "BL_bBGbASH2RnPCskt","FlowID": "FL_59"},{"Type": "WebService","FlowID": "FL_50","URL": "https://co1.qualtrics.com/API/v3/surveys","Method": "POST","RequestParams": [],"EditBodyParams": [{"key": "file","value": "${e://Field/TEST}"},{"key": "name","value": "new survey"}],"Body": [{"key": "file","value": "${e://Field/TEST}"},{"key": "name","value": "new survey"}],"ContentType": "application/x-www-form-urlencoded","Headers": [{"key": "x-api-token","value": "h69TKYgxu46SMEXzcKkeRUXovq2jALTpHDhPUGLq"}],"ResponseMap": [{"key": "meta.requestId","value": "meta.requestId"},{"key": "meta.error.errorCode","value": "meta.error.errorCode"},{"key": "meta.error.errorMessage","value": "meta.error.errorMessage"},{"key": "meta.httpStatus","value": "meta.httpStatus"}],"FireAndForget": false,"SchemaVersion": 0,"StringifyValues": true},{"Type": "Standard","ID": "BL_4Yhl7MpygFG9Z6B","FlowID": "FL_53"}]},{"Type": "Standard","ID": "BL_0GHahOV7Hb9l141","FlowID": "FL_3"},{"Type": "Branch","FlowID": "FL_5","Description": "New Branch","BranchLogic": {"0": {"0": {"LogicType": "Question","QuestionID": "QID4","QuestionIsInLoop": "no","ChoiceLocator": "q://QID4/SelectableChoice/1","Operator": "Selected","QuestionIDFromLocator": "QID4","LeftOperand": "q://QID4/SelectableChoice/1","Type": "Expression","Description": "<span class=\"ConjDesc\">If</span> <span class=\"QuestionDesc\">What would you like to do?</span> <span class=\"LeftOpDesc\">Check if there is custom validation/Force Response on my survey and on what questions</span> <span class=\"OpDesc\">Is Selected</span> "},"Type": "If"},"Type": "BooleanExpression"},"Flow": [{"Type": "Block","ID": "BL_3n1Vmp4FL6cZZuR","FlowID": "FL_2"},{"Type": "EndSurvey","FlowID": "FL_11"}]},{"Type": "Branch","FlowID": "FL_56","Description": "New Branch","BranchLogic": {"0": {"0": {"LogicType": "Question","QuestionID": "QID4","QuestionIsInLoop": "no","ChoiceLocator": "q://QID4/SelectableChoice/6","Operator": "Selected","QuestionIDFromLocator": "QID4","LeftOperand": "q://QID4/SelectableChoice/6","Type": "Expression","Description": "<span class=\"ConjDesc\">If</span> <span class=\"QuestionDesc\">What would you like to do?</span> <span class=\"LeftOpDesc\">Re-Number the questions to be in order but add \"TEXT\" to descriptive text questions.</span> <span class=\"OpDesc\">Is Selected</span> "},"Type": "If"},"Type": "BooleanExpression"},"Flow": [{"Type": "Standard","ID": "BL_9ESRPcpuMl5TNcx","FlowID": "FL_60"},{"ID": "BL_cACgbdijKOAtRo9","Type": "Standard","FlowID": "FL_61"},{"Type": "Standard","ID": "BL_0SuWoa7K2CkYFsV","FlowID": "FL_55"}]},{"Type": "Branch","FlowID": "FL_58","Description": "New Branch","BranchLogic": {"0": {"0": {"LogicType": "Question","QuestionID": "QID4","QuestionIsInLoop": "no","ChoiceLocator": "q://QID4/SelectableChoice/6","Operator": "NotSelected","QuestionIDFromLocator": "QID4","LeftOperand": "q://QID4/SelectableChoice/6","Type": "Expression","Description": "<span class=\"ConjDesc\">If</span> <span class=\"QuestionDesc\">What would you like to do?</span> <span class=\"LeftOpDesc\">Re-Number the questions to be in order but add \"TEXT\" to descriptive text questions.</span> <span class=\"OpDesc\">Is Not Selected</span> "},"Type": "If"},"Type": "BooleanExpression"},"Flow": [{"Type": "Standard","ID": "BL_2tA1Ilad6iCEEu1","FlowID": "FL_13"},{"Type": "EmbeddedData","FlowID": "FL_14","EmbeddedData": [{"Description": "APIToken","Type": "Custom","Field": "APIToken","VariableType": "String","DataVisibility": [],"AnalyzeText": false,"Value": "${q://QID18/ChoiceTextEntryValue/2}"},{"Description": "Datacenter","Type": "Custom","Field": "Datacenter","VariableType": "String","DataVisibility": [],"AnalyzeText": false,"Value": "${q://QID18/ChoiceTextEntryValue/1}"}]},{"Type": "Standard","ID": "BL_0r1ZjeAhMBEBhdz","FlowID": "FL_4"},{"Type": "Branch","FlowID": "FL_21","Description": "New Branch","BranchLogic": {"0": {"0": {"LogicType": "Question","QuestionID": "QID17","QuestionIsInLoop": "no","ChoiceLocator": "q://QID17/SelectableChoice/4","Operator": "Selected","QuestionIDFromLocator": "QID17","LeftOperand": "q://QID17/SelectableChoice/4","Type": "Expression","Description": "<span class=\"ConjDesc\">If</span> <span class=\"QuestionDesc\">What type of questions will you be using?</span> <span class=\"LeftOpDesc\">matrix choice to multiple choice question</span> <span class=\"OpDesc\">Is Selected</span> "},"Type": "If"},"Type": "BooleanExpression"},"Flow": [{"Type": "Standard","ID": "BL_6ilSpb6iiCzWvtz","FlowID": "FL_20"},{"Type": "Standard","ID": "BL_a4faBNVnTi19wLr","FlowID": "FL_23"},{"Type": "EmbeddedData","FlowID": "FL_25","EmbeddedData": [{"Description": "Conjunction","Type": "Custom","Field": "Conjunction","VariableType": "String","DataVisibility": [],"AnalyzeText": false,"Value": "${q://QID32/ChoiceGroup/SelectedChoices}"}]},{"Type": "EmbeddedData","FlowID": "FL_26","EmbeddedData": [{"Description": "Operator","Type": "Custom","Field": "Operator","VariableType": "String","DataVisibility": [],"AnalyzeText": false,"Value": "${q://QID29/ChoiceGroup/SelectedChoices}"}]},{"Type": "Standard","ID": "BL_2lVBP4EOiOwT0Kp","FlowID": "FL_24"}]},{"Type": "Branch","FlowID": "FL_6","Description": "New Branch","BranchLogic": {"0": {"0": {"LogicType": "Question","QuestionID": "QID17","QuestionIsInLoop": "no","ChoiceLocator": "q://QID17/SelectableChoice/1","Operator": "Selected","QuestionIDFromLocator": "QID17","LeftOperand": "q://QID17/SelectableChoice/1","Type": "Expression","Description": "<span class=\"ConjDesc\">If</span> <span class=\"QuestionDesc\">What type of questions will you be using?</span> <span class=\"LeftOpDesc\">multiple choice to multiple choice</span> <span class=\"OpDesc\">Is Selected</span> "},"Type": "If"},"Type": "BooleanExpression"},"Flow": [{"Type": "EmbeddedData","FlowID": "FL_10","EmbeddedData": [{"Description": "Operator","Type": "Custom","Field": "Operator","VariableType": "String","DataVisibility": [],"AnalyzeText": false,"Value": "${q://QID13/ChoiceGroup/SelectedChoices}"}]},{"Type": "Standard","ID": "BL_4IMpxjrEATyLuqV","FlowID": "FL_19"},{"Type": "Standard","ID": "BL_bBjaPeuYnHFtBBP","FlowID": "FL_9"}]}]},{"Type": "Standard","ID": "BL_eD0WiECJYD2l0nr","FlowID": "FL_28"}]},{"Type": "Standard","ID": "BL_1Mk6LuLiukBnCU5","FlowID": "FL_17"},{"Type": "EndSurvey","FlowID": "FL_16"},{"Type": "WebService","FlowID": "FL_15","URL": "https://co1.qualtrics.com/API/v:version/surveys","Method": "PUT","RequestParams": [],"EditBodyParams": [{"key": "QuestionText","value": "Hello"},{"key": "DataExportTag","value": "Q2"},{"key": "QuestionType","value": "MC"},{"key": "Selector","value": "SAVR"},{"key": "SubSelector","value": "TX"},{"key": "Configuration","value": "{\"QuestionDescriptionOption\":\"UseText\"}","parameterType": "JSON"},{"key": "QuestionDescription","value": "Hello?"},{"key": "Choices","value": "{\"Choices\": {\n          \"1\": {\n            \"Display\": \"Statement 1\"\n          },\n          \"2\": {\n            \"Display\": \"Statement 2\"\n          },\n          \"3\": {\n            \"Display\": \"Statement 3\"\n          }\n        }}","parameterType": "JSON"},{"key": "Language","value": "[]","parameterType": "JSON"},{"key": "Validation","value": "{\"Settings\": {\n            \"ForceResponse\": \"OFF\",\n            \"ForceResponseType\": \"ON\",\n            \"Type\": \"None\"\n          }}","parameterType": "JSON"}],"Body": {"QuestionText": "Hello","DataExportTag": "Q2","QuestionType": "MC","Selector": "SAVR","SubSelector": "TX","Configuration": {"QuestionDescriptionOption": "UseText"},"QuestionDescription": "Hello?","Choices": {"Choices": {"1": {"Display": "Statement 1"},"2": {"Display": "Statement 2"},"3": {"Display": "Statement 3"}}},"Language": [],"Validation": {"Settings": {"ForceResponse": "OFF","ForceResponseType": "ON","Type": "None"}}},"ContentType": "application/json","Headers": [{"key": "x-api-token","value": "h69TKYgxu46SMEXzcKkeRUXovq2jALTpHDhPUGLq"}],"ResponseMap": [],"FireAndForget": false,"SchemaVersion": 0,"StringifyValues": true}],"Properties": {"Count": 61,"RemovedFieldsets": []}}

function getID(arr){
  if (!arr || arr.length == 0 ) return []
  return arr.reduce((arr, item) =>{
    if (item.Type == "Standard"  || item.Type == "Block") {
      arr.push(item.ID)  
    }
    return arr.concat(getID(item.Flow))
  }, [])
}

let fl = getID([Payload])

console.log("length: ", fl.length)
console.log(fl)