Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/454.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/83.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从JSON数据生成JSON_Javascript_Jquery_Node.js_Arrays_Json - Fatal编程技术网

Javascript 从JSON数据生成JSON

Javascript 从JSON数据生成JSON,javascript,jquery,node.js,arrays,json,Javascript,Jquery,Node.js,Arrays,Json,我有下面的JSON数据。我需要JSON来拆分并形成一个新的JSON数据对象。 我是新手,正在努力找到解决这个问题的方法 JSON数据下方: [ { "timestamp":"2020-11-13T20:57:17.611Z", "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a", "Telephone":

我有下面的JSON数据。我需要JSON来拆分并形成一个新的JSON数据对象。 我是新手,正在努力找到解决这个问题的方法

JSON数据下方:

[
   {
      "timestamp":"2020-11-13T20:57:17.611Z",
      "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
      "Telephone":"555555555",
      "Name":"Mike",
      "Thread":[
         {
            "textPayload":{
               "timestamp":"2020-11-13T20:57:08.552Z",
               "id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf",
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "lang":"en",
               "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
               "result":{
                  "score":1,
                  "action_incomplete":true,
                  "resolved_query":"hi",
                  "action":"input.welcome",
                  "source":"agent",
                  "metadata":{
                     "intent_name":"Default Welcome Intent",
                     "webhook_used":false,
                     "intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
                     "is_fallback_intent":false,
                     "webhook_for_slot_filling_used":false
                  },
                  "parameters":{
                     "fields":{
                        "value":{
                           "string_value":""
                        },
                        "key":"name"
                     }
                  },
                  "contexts":{
                     "parameters":{
                        "fields":{
                           "key":"no-match",
                           "value":{
                              "number_value":0
                           }
                        }
                     },
                     "name":"__system_counters__",
                     "lifespan":1
                  },
                  "fulfillment":{
                     "messages":{
                        "type":{
                           "number_value":0
                        },
                        "speech":{
                           "string_value":"What is the name?"
                        }
                     },
                     "speech":"What is the name?"
                  }
               }
            },
            "insertId":"1p1x1wdfgkwf2a",
            "severity":"INFO",
            "receiveTimestamp":"2020-11-13T20:57:08.592891686Z",
            "trace":"eed8d600-0438-37d3-dd96-25081a91b90a",
            "labels":{
               "request_id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf",
               "type":"dialogflow_response",
               "protocol":"V2_BETA1",
               "source":"DIALOGFLOW_CONSOLE"
            },
            "timestamp":"2020-11-13T20:57:08.571Z",
            "logName":"projects/entuber/logs/dialogflow_agent",
            "resource":{
               "type":"global",
               "labels":{
                  "project_id":"entuber"
               }
            },
            "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a"
         },
         {
            "timestamp":"2020-11-13T20:57:11.746Z",
            "labels":{
               "type":"dialogflow_response",
               "protocol":"V2_BETA1",
               "source":"DIALOGFLOW_CONSOLE",
               "request_id":"70b25970-e228-41b9-9898-26d68bb67c13-aabf4fdf"
            },
            "resource":{
               "labels":{
                  "project_id":"entuber"
               },
               "type":"global"
            },
            "logName":"projects/entuber/logs/dialogflow_agent",
            "receiveTimestamp":"2020-11-13T20:57:11.766438485Z",
            "trace":"eed8d600-0438-37d3-dd96-25081a91b90a",
            "severity":"INFO",
            "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
            "textPayload":{
               "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
               "status":{
                  "code":200,
                  "error_type":"success"
               },
               "timestamp":"2020-11-13T20:57:11.728Z",
               "id":"70b25970-e228-41b9-9898-26d68bb67c13-aabf4fdf",
               "lang":"en",
               "result":{
                  "contexts":{
                     "lifespan":50,
                     "parameters":{
                        "fields":{
                           "value":{
                              "string_value":"sam"
                           },
                           "key":"name.original"
                        }
                     },
                     "name":"name"
                  },
                  "action":"input.welcome",
                  "resolved_query":"sam",
                  "fulfillment":{
                     "speech":"Hi, I'm Tara. I've been modified to tell you what your bills are. Ask me for your current bill and I'll tell you how much you have to pay and when it's due. Make sure you know the account number though.",
                     "messages":{
                        "speech":{
                           "string_value":""
                        },
                        "lang":"en",
                        "type":{
                           "number_value":0
                        }
                     }
                  },
                  "parameters":{
                     "fields":{
                        "key":"name",
                        "value":{
                           "string_value":"Sam"
                        }
                     }
                  },
                  "metadata":{
                     "intent_name":"Default Welcome Intent",
                     "is_fallback_intent":false,
                     "intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
                     "webhook_for_slot_filling_used":false,
                     "webhook_used":false
                  },
                  "source":"agent",
                  "score":1
               }
            },
            "insertId":"1orjxuhfg78gle"
         },
      ]
   },
   {
      "session_id":"TestTaraSession",
      "timestamp":"2020-11-16T06:17:37.536Z",
      "Thread":[
         {
            "resource":{
               "type":"global",
               "labels":{
                  "project_id":"entuber"
               }
            },
            "insertId":"ftk71rg38zc3de",
            "trace":"TestTaraSession",
            "logName":"projects/entuber/logs/dialogflow_agent",
            "labels":{
               "type":"dialogflow_response",
               "request_id":"1fd35e1d-7830-4606-937d-b8685dde0129-aabf4fdf",
               "protocol":"V2_BETA1"
            },
            "severity":"INFO",
            "timestamp":"2020-11-16T06:16:50.421Z",
            "session_id":"TestTaraSession",
            "receiveTimestamp":"2020-11-16T06:16:50.45315191Z",
            "textPayload":{
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "id":"1fd35e1d-7830-4606-937d-b8685dde0129-aabf4fdf",
               "lang":"en",
               "session_id":"TestTaraSession",
               "result":{
                  "score":1,
                  "parameters":{
                     "fields":{
                        "value":{
                           "string_value":""
                        },
                        "key":"name"
                     }
                  },
                  "metadata":{
                     "intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
                     "is_fallback_intent":false,
                     "webhook_used":false,
                     "intent_name":"Default Welcome Intent",
                     "webhook_for_slot_filling_used":false
                  },
                  "action":"input.welcome",
                  "contexts":{
                     "lifespan":1,
                     "name":"__system_counters__",
                     "parameters":{
                        "fields":{
                           "value":{
                              "number_value":0
                           },
                           "key":"no-match"
                        }
                     }
                  },
                  "action_incomplete":true,
                  "fulfillment":{
                     "messages":{
                        "type":{
                           "number_value":0
                        },
                        "speech":{
                           "string_value":"What is the name?"
                        }
                     },
                     "speech":"What is the name?"
                  },
                  "source":"agent",
                  "resolved_query":"WELCOME"
               },
               "timestamp":"2020-11-16T06:16:50.408Z"
            }
         },
         {
            "session_id":"TestTaraSession",
            "timestamp":"2020-11-16T06:17:08.746Z",
            "insertId":"1ggf79rg3d2lksr",
            "labels":{
               "protocol":"V2_BETA1",
               "type":"dialogflow_response",
               "request_id":"ff18d72b-5fbc-4e44-a52d-f987d0d59d9d-aabf4fdf"
            },
            "logName":"projects/entuber/logs/dialogflow_agent",
            "receiveTimestamp":"2020-11-16T06:17:08.756453598Z",
            "trace":"TestTaraSession",
            "textPayload":{
               "session_id":"TestTaraSession",
               "lang":"en",
               "result":{
                  "contexts":{
                     "parameters":{
                        "fields":{
                           "value":{
                              "string_value":"Tara"
                           },
                           "key":"name.original"
                        }
                     },
                     "lifespan":50,
                     "name":"name"
                  },
                  "metadata":{
                     "intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
                     "is_fallback_intent":false,
                     "webhook_used":false,
                     "webhook_for_slot_filling_used":false,
                     "intent_name":"Default Welcome Intent"
                  },
                  "parameters":{
                     "fields":{
                        "value":{
                           "string_value":"Tara"
                        },
                        "key":"name"
                     }
                  },
                  "action":"input.welcome",
                  "source":"agent",
                  "score":1,
                  "fulfillment":{
                     "messages":{
                        "lang":"en",
                        "speech":{
                           "string_value":""
                        },
                        "type":{
                           "number_value":0
                        }
                     },
                     "speech":"Hi, I'm Tara. I've been modified to tell you what your bills are. Ask me for your current bill and I'll tell you how much you have to pay and when it's due. Make sure you know the account number though."
                  },
                  "resolved_query":"Tara"
               },
               "timestamp":"2020-11-16T06:17:08.742Z",
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "id":"ff18d72b-5fbc-4e44-a52d-f987d0d59d9d-aabf4fdf"
            },
            "severity":"INFO",
            "resource":{
               "labels":{
                  "project_id":"entuber"
               },
               "type":"global"
            }
         },
         {
            "trace":"TestTaraSession",
            "receiveTimestamp":"2020-11-16T06:17:17.973535789Z",
            "logName":"projects/entuber/logs/dialogflow_agent",
            "textPayload":{
               "lang":"en",
               "timestamp":"2020-11-16T06:17:17.943Z",
               "result":{
                  "score":0.686966,
                  "parameters":{
                     "fields":{
                        "value":{
                           "string_value":""
                        },
                        "key":"accountNo"
                     }
                  },
                  "action":"com.tara.bills",
                  "metadata":{
                     "intent_id":"5ff968ab-3646-4abe-ae7e-93203997e5fb",
                     "webhook_used":true,
                     "webhook_for_slot_filling_used":false,
                     "intent_name":"Read Bill",
                     "is_fallback_intent":false
                  },
                  "resolved_query":"Bill details",
                  "action_incomplete":true,
                  "source":"agent",
                  "fulfillment":{
                     "messages":{
                        "speech":{
                           "string_value":"What is your account number?"
                        },
                        "type":{
                           "number_value":0
                        }
                     },
                     "speech":"What is your account number?"
                  },
                  "contexts":{
                     "parameters":{
                        "fields":{
                           "key":"no-match",
                           "value":{
                              "number_value":0
                           }
                        }
                     },
                     "name":"__system_counters__",
                     "lifespan":1
                  }
               },
               "id":"ab128f85-0044-42ba-ae8a-c77d0905d972-aabf4fdf",
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "session_id":"TestTaraSession"
            },
            "severity":"INFO",
            "session_id":"TestTaraSession",
            "resource":{
               "labels":{
                  "project_id":"entuber"
               },
               "type":"global"
            },
            "timestamp":"2020-11-16T06:17:17.965Z",
            "insertId":"dc02v6g3eo2vya",
            "labels":{
               "type":"dialogflow_response",
               "protocol":"V2_BETA1",
               "request_id":"ab128f85-0044-42ba-ae8a-c77d0905d972-aabf4fdf"
            }
         },
         {
            "textPayload":{
               "session_id":"TestTaraSession",
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "result":{
                  "metadata":{
                     "webhook_used":false,
                     "intent_name":"Read Bill",
                     "webhook_response_time":3334,
                     "intent_id":"5ff968ab-3646-4abe-ae7e-93203997e5fb",
                     "is_fallback_intent":false,
                     "webhook_for_slot_filling_used":false
                  },
                  "contexts":{
                     "name":"defaultwelcomeintent-followup",
                     "lifespan":1,
                     "parameters":{
                        "fields":{
                           "value":{
                              "string_value":"Tara"
                           },
                           "key":"name.original"
                        }
                     }
                  },
                  "source":"agent",
                  "action":"com.tara.bills",
                  "fulfillment":{
                     "speech":"Your current bill of $2927.62 is due on 10/19/2020.",
                     "messages":{
                        "speech":{
                           "string_value":"Your current bill of $2927.62 is due on 10/19/2020."
                        },
                        "type":{
                           "number_value":0
                        }
                     }
                  },
                  "score":1,
                  "parameters":{
                     "fields":{
                        "value":{
                           "number_value":21012875
                        },
                        "key":"accountNo"
                     }
                  },
                  "resolved_query":21012875
               },
               "lang":"en",
               "id":"1d3df1d2-1753-48fc-948e-7fc91473d055-aabf4fdf",
               "timestamp":"2020-11-16T06:17:34.184Z"
            },
            "insertId":"1def6i1g15mb48l",
            "labels":{
               "protocol":"V2_BETA1",
               "request_id":"1d3df1d2-1753-48fc-948e-7fc91473d055-aabf4fdf",
               "type":"dialogflow_response"
            },
            "receiveTimestamp":"2020-11-16T06:17:37.548546643Z",
            "timestamp":"2020-11-16T06:17:37.536Z",
            "severity":"INFO",
            "resource":{
               "type":"global",
               "labels":{
                  "project_id":"entuber"
               }
            },
            "session_id":"TestTaraSession",
            "trace":"TestTaraSession",
            "logName":"projects/entuber/logs/dialogflow_agent"
         }
      ]
   },
   {
      "timestamp":"2020-11-16T06:29:14.564Z",
      "session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
      "Thread":[
         {
            "timestamp":"2020-11-16T06:29:01.638Z",
            "session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
            "logName":"projects/entuber/logs/dialogflow_agent",
            "severity":"INFO",
            "insertId":"1httvn0g2nj3fae",
            "labels":{
               "request_id":"94ec1661-d472-4ef0-a7bd-d85e22062e4d-aabf4fdf",
               "protocol":"V2_BETA1",
               "type":"dialogflow_response",
               "source":"DIALOGFLOW_CONSOLE"
            },
            "trace":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
            "resource":{
               "labels":{
                  "project_id":"entuber"
               },
               "type":"global"
            },
            "textPayload":{
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
               "result":{
                  "resolved_query":"hello",
                  "contexts":{
                     "parameters":{
                        "fields":{
                           "key":"no-match",
                           "value":{
                              "number_value":0
                           }
                        }
                     },
                     "lifespan":1,
                     "name":"__system_counters__"
                  },
                  "score":1,
                  "action_incomplete":true,
                  "fulfillment":{
                     "messages":{
                        "speech":{
                           "string_value":"What is the name?"
                        },
                        "type":{
                           "number_value":0
                        }
                     },
                     "speech":"What is the name?"
                  },
                  "action":"input.welcome",
                  "metadata":{
                     "is_fallback_intent":false,
                     "intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
                     "webhook_for_slot_filling_used":false,
                     "webhook_used":false,
                     "intent_name":"Default Welcome Intent"
                  },
                  "parameters":{
                     "fields":{
                        "key":"name",
                        "value":{
                           "string_value":""
                        }
                     }
                  },
                  "source":"agent"
               },
               "id":"94ec1661-d472-4ef0-a7bd-d85e22062e4d-aabf4fdf",
               "timestamp":"2020-11-16T06:29:01.596Z",
               "lang":"en"
            },
            "receiveTimestamp":"2020-11-16T06:29:01.64859801Z"
         },
         {
            "severity":"INFO",
            "receiveTimestamp":"2020-11-16T06:29:07.676213264Z",
            "resource":{
               "type":"global",
               "labels":{
                  "project_id":"entuber"
               }
            },
            "insertId":"13ojz2yg2npq0nk",
            "labels":{
               "source":"DIALOGFLOW_CONSOLE",
               "type":"dialogflow_response",
               "request_id":"896b6d41-fe8b-4123-ba68-07004435db42-aabf4fdf",
               "protocol":"V2_BETA1"
            },
            "timestamp":"2020-11-16T06:29:07.667Z",
            "logName":"projects/entuber/logs/dialogflow_agent",
            "trace":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
            "textPayload":{
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "timestamp":"2020-11-16T06:29:07.62Z",
               "lang":"en",
               "result":{
                  "contexts":{
                     "lifespan":50,
                     "name":"name",
                     "parameters":{
                        "fields":{
                           "key":"name.original",
                           "value":{
                              "string_value":"tara"
                           }
                        }
                     }
                  },
                  "source":"agent",
                  "resolved_query":"tara",
                  "score":1,
                  "action":"input.welcome",
                  "fulfillment":{
                     "messages":{
                        "lang":"en",
                        "speech":{
                           "string_value":""
                        },
                        "type":{
                           "number_value":0
                        }
                     },
                     "speech":"Can I have your name?"
                  },
                  "parameters":{
                     "fields":{
                        "key":"name",
                        "value":{
                           "string_value":"Tara"
                        }
                     }
                  },
                  "metadata":{
                     "webhook_for_slot_filling_used":false,
                     "is_fallback_intent":false,
                     "intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
                     "intent_name":"Default Welcome Intent",
                     "webhook_used":false
                  }
               },
               "id":"896b6d41-fe8b-4123-ba68-07004435db42-aabf4fdf",
               "session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804"
            },
            "session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804"
         }
      ]
   }
]
[
   {
      "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
      "timestamp":"2020-11-13T20:57:17.611Z",
      "labels":{
         "request_id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf",
         "type":"dialogflow_response",
         "protocol":"V2_BETA1",
         "source":"DIALOGFLOW_CONSOLE"
      },
      "Thread":[
         {
            "speech":"What is the name?",
            "timestamp":"2020-11-13T20:57:08.552Z",
            "id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf"
         }
      ]
   }
]
必须对输入JSON数据中的所有
session\u id
值执行此操作。 它必须形成所有JSON数据,以迭代并在另一个HTML中显示。 我在这里感到困惑,我的目标是: 样本输出:

[
   {
      "timestamp":"2020-11-13T20:57:17.611Z",
      "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
      "Telephone":"555555555",
      "Name":"Mike",
      "Thread":[
         {
            "textPayload":{
               "timestamp":"2020-11-13T20:57:08.552Z",
               "id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf",
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "lang":"en",
               "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
               "result":{
                  "score":1,
                  "action_incomplete":true,
                  "resolved_query":"hi",
                  "action":"input.welcome",
                  "source":"agent",
                  "metadata":{
                     "intent_name":"Default Welcome Intent",
                     "webhook_used":false,
                     "intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
                     "is_fallback_intent":false,
                     "webhook_for_slot_filling_used":false
                  },
                  "parameters":{
                     "fields":{
                        "value":{
                           "string_value":""
                        },
                        "key":"name"
                     }
                  },
                  "contexts":{
                     "parameters":{
                        "fields":{
                           "key":"no-match",
                           "value":{
                              "number_value":0
                           }
                        }
                     },
                     "name":"__system_counters__",
                     "lifespan":1
                  },
                  "fulfillment":{
                     "messages":{
                        "type":{
                           "number_value":0
                        },
                        "speech":{
                           "string_value":"What is the name?"
                        }
                     },
                     "speech":"What is the name?"
                  }
               }
            },
            "insertId":"1p1x1wdfgkwf2a",
            "severity":"INFO",
            "receiveTimestamp":"2020-11-13T20:57:08.592891686Z",
            "trace":"eed8d600-0438-37d3-dd96-25081a91b90a",
            "labels":{
               "request_id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf",
               "type":"dialogflow_response",
               "protocol":"V2_BETA1",
               "source":"DIALOGFLOW_CONSOLE"
            },
            "timestamp":"2020-11-13T20:57:08.571Z",
            "logName":"projects/entuber/logs/dialogflow_agent",
            "resource":{
               "type":"global",
               "labels":{
                  "project_id":"entuber"
               }
            },
            "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a"
         },
         {
            "timestamp":"2020-11-13T20:57:11.746Z",
            "labels":{
               "type":"dialogflow_response",
               "protocol":"V2_BETA1",
               "source":"DIALOGFLOW_CONSOLE",
               "request_id":"70b25970-e228-41b9-9898-26d68bb67c13-aabf4fdf"
            },
            "resource":{
               "labels":{
                  "project_id":"entuber"
               },
               "type":"global"
            },
            "logName":"projects/entuber/logs/dialogflow_agent",
            "receiveTimestamp":"2020-11-13T20:57:11.766438485Z",
            "trace":"eed8d600-0438-37d3-dd96-25081a91b90a",
            "severity":"INFO",
            "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
            "textPayload":{
               "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
               "status":{
                  "code":200,
                  "error_type":"success"
               },
               "timestamp":"2020-11-13T20:57:11.728Z",
               "id":"70b25970-e228-41b9-9898-26d68bb67c13-aabf4fdf",
               "lang":"en",
               "result":{
                  "contexts":{
                     "lifespan":50,
                     "parameters":{
                        "fields":{
                           "value":{
                              "string_value":"sam"
                           },
                           "key":"name.original"
                        }
                     },
                     "name":"name"
                  },
                  "action":"input.welcome",
                  "resolved_query":"sam",
                  "fulfillment":{
                     "speech":"Hi, I'm Tara. I've been modified to tell you what your bills are. Ask me for your current bill and I'll tell you how much you have to pay and when it's due. Make sure you know the account number though.",
                     "messages":{
                        "speech":{
                           "string_value":""
                        },
                        "lang":"en",
                        "type":{
                           "number_value":0
                        }
                     }
                  },
                  "parameters":{
                     "fields":{
                        "key":"name",
                        "value":{
                           "string_value":"Sam"
                        }
                     }
                  },
                  "metadata":{
                     "intent_name":"Default Welcome Intent",
                     "is_fallback_intent":false,
                     "intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
                     "webhook_for_slot_filling_used":false,
                     "webhook_used":false
                  },
                  "source":"agent",
                  "score":1
               }
            },
            "insertId":"1orjxuhfg78gle"
         },
      ]
   },
   {
      "session_id":"TestTaraSession",
      "timestamp":"2020-11-16T06:17:37.536Z",
      "Thread":[
         {
            "resource":{
               "type":"global",
               "labels":{
                  "project_id":"entuber"
               }
            },
            "insertId":"ftk71rg38zc3de",
            "trace":"TestTaraSession",
            "logName":"projects/entuber/logs/dialogflow_agent",
            "labels":{
               "type":"dialogflow_response",
               "request_id":"1fd35e1d-7830-4606-937d-b8685dde0129-aabf4fdf",
               "protocol":"V2_BETA1"
            },
            "severity":"INFO",
            "timestamp":"2020-11-16T06:16:50.421Z",
            "session_id":"TestTaraSession",
            "receiveTimestamp":"2020-11-16T06:16:50.45315191Z",
            "textPayload":{
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "id":"1fd35e1d-7830-4606-937d-b8685dde0129-aabf4fdf",
               "lang":"en",
               "session_id":"TestTaraSession",
               "result":{
                  "score":1,
                  "parameters":{
                     "fields":{
                        "value":{
                           "string_value":""
                        },
                        "key":"name"
                     }
                  },
                  "metadata":{
                     "intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
                     "is_fallback_intent":false,
                     "webhook_used":false,
                     "intent_name":"Default Welcome Intent",
                     "webhook_for_slot_filling_used":false
                  },
                  "action":"input.welcome",
                  "contexts":{
                     "lifespan":1,
                     "name":"__system_counters__",
                     "parameters":{
                        "fields":{
                           "value":{
                              "number_value":0
                           },
                           "key":"no-match"
                        }
                     }
                  },
                  "action_incomplete":true,
                  "fulfillment":{
                     "messages":{
                        "type":{
                           "number_value":0
                        },
                        "speech":{
                           "string_value":"What is the name?"
                        }
                     },
                     "speech":"What is the name?"
                  },
                  "source":"agent",
                  "resolved_query":"WELCOME"
               },
               "timestamp":"2020-11-16T06:16:50.408Z"
            }
         },
         {
            "session_id":"TestTaraSession",
            "timestamp":"2020-11-16T06:17:08.746Z",
            "insertId":"1ggf79rg3d2lksr",
            "labels":{
               "protocol":"V2_BETA1",
               "type":"dialogflow_response",
               "request_id":"ff18d72b-5fbc-4e44-a52d-f987d0d59d9d-aabf4fdf"
            },
            "logName":"projects/entuber/logs/dialogflow_agent",
            "receiveTimestamp":"2020-11-16T06:17:08.756453598Z",
            "trace":"TestTaraSession",
            "textPayload":{
               "session_id":"TestTaraSession",
               "lang":"en",
               "result":{
                  "contexts":{
                     "parameters":{
                        "fields":{
                           "value":{
                              "string_value":"Tara"
                           },
                           "key":"name.original"
                        }
                     },
                     "lifespan":50,
                     "name":"name"
                  },
                  "metadata":{
                     "intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
                     "is_fallback_intent":false,
                     "webhook_used":false,
                     "webhook_for_slot_filling_used":false,
                     "intent_name":"Default Welcome Intent"
                  },
                  "parameters":{
                     "fields":{
                        "value":{
                           "string_value":"Tara"
                        },
                        "key":"name"
                     }
                  },
                  "action":"input.welcome",
                  "source":"agent",
                  "score":1,
                  "fulfillment":{
                     "messages":{
                        "lang":"en",
                        "speech":{
                           "string_value":""
                        },
                        "type":{
                           "number_value":0
                        }
                     },
                     "speech":"Hi, I'm Tara. I've been modified to tell you what your bills are. Ask me for your current bill and I'll tell you how much you have to pay and when it's due. Make sure you know the account number though."
                  },
                  "resolved_query":"Tara"
               },
               "timestamp":"2020-11-16T06:17:08.742Z",
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "id":"ff18d72b-5fbc-4e44-a52d-f987d0d59d9d-aabf4fdf"
            },
            "severity":"INFO",
            "resource":{
               "labels":{
                  "project_id":"entuber"
               },
               "type":"global"
            }
         },
         {
            "trace":"TestTaraSession",
            "receiveTimestamp":"2020-11-16T06:17:17.973535789Z",
            "logName":"projects/entuber/logs/dialogflow_agent",
            "textPayload":{
               "lang":"en",
               "timestamp":"2020-11-16T06:17:17.943Z",
               "result":{
                  "score":0.686966,
                  "parameters":{
                     "fields":{
                        "value":{
                           "string_value":""
                        },
                        "key":"accountNo"
                     }
                  },
                  "action":"com.tara.bills",
                  "metadata":{
                     "intent_id":"5ff968ab-3646-4abe-ae7e-93203997e5fb",
                     "webhook_used":true,
                     "webhook_for_slot_filling_used":false,
                     "intent_name":"Read Bill",
                     "is_fallback_intent":false
                  },
                  "resolved_query":"Bill details",
                  "action_incomplete":true,
                  "source":"agent",
                  "fulfillment":{
                     "messages":{
                        "speech":{
                           "string_value":"What is your account number?"
                        },
                        "type":{
                           "number_value":0
                        }
                     },
                     "speech":"What is your account number?"
                  },
                  "contexts":{
                     "parameters":{
                        "fields":{
                           "key":"no-match",
                           "value":{
                              "number_value":0
                           }
                        }
                     },
                     "name":"__system_counters__",
                     "lifespan":1
                  }
               },
               "id":"ab128f85-0044-42ba-ae8a-c77d0905d972-aabf4fdf",
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "session_id":"TestTaraSession"
            },
            "severity":"INFO",
            "session_id":"TestTaraSession",
            "resource":{
               "labels":{
                  "project_id":"entuber"
               },
               "type":"global"
            },
            "timestamp":"2020-11-16T06:17:17.965Z",
            "insertId":"dc02v6g3eo2vya",
            "labels":{
               "type":"dialogflow_response",
               "protocol":"V2_BETA1",
               "request_id":"ab128f85-0044-42ba-ae8a-c77d0905d972-aabf4fdf"
            }
         },
         {
            "textPayload":{
               "session_id":"TestTaraSession",
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "result":{
                  "metadata":{
                     "webhook_used":false,
                     "intent_name":"Read Bill",
                     "webhook_response_time":3334,
                     "intent_id":"5ff968ab-3646-4abe-ae7e-93203997e5fb",
                     "is_fallback_intent":false,
                     "webhook_for_slot_filling_used":false
                  },
                  "contexts":{
                     "name":"defaultwelcomeintent-followup",
                     "lifespan":1,
                     "parameters":{
                        "fields":{
                           "value":{
                              "string_value":"Tara"
                           },
                           "key":"name.original"
                        }
                     }
                  },
                  "source":"agent",
                  "action":"com.tara.bills",
                  "fulfillment":{
                     "speech":"Your current bill of $2927.62 is due on 10/19/2020.",
                     "messages":{
                        "speech":{
                           "string_value":"Your current bill of $2927.62 is due on 10/19/2020."
                        },
                        "type":{
                           "number_value":0
                        }
                     }
                  },
                  "score":1,
                  "parameters":{
                     "fields":{
                        "value":{
                           "number_value":21012875
                        },
                        "key":"accountNo"
                     }
                  },
                  "resolved_query":21012875
               },
               "lang":"en",
               "id":"1d3df1d2-1753-48fc-948e-7fc91473d055-aabf4fdf",
               "timestamp":"2020-11-16T06:17:34.184Z"
            },
            "insertId":"1def6i1g15mb48l",
            "labels":{
               "protocol":"V2_BETA1",
               "request_id":"1d3df1d2-1753-48fc-948e-7fc91473d055-aabf4fdf",
               "type":"dialogflow_response"
            },
            "receiveTimestamp":"2020-11-16T06:17:37.548546643Z",
            "timestamp":"2020-11-16T06:17:37.536Z",
            "severity":"INFO",
            "resource":{
               "type":"global",
               "labels":{
                  "project_id":"entuber"
               }
            },
            "session_id":"TestTaraSession",
            "trace":"TestTaraSession",
            "logName":"projects/entuber/logs/dialogflow_agent"
         }
      ]
   },
   {
      "timestamp":"2020-11-16T06:29:14.564Z",
      "session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
      "Thread":[
         {
            "timestamp":"2020-11-16T06:29:01.638Z",
            "session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
            "logName":"projects/entuber/logs/dialogflow_agent",
            "severity":"INFO",
            "insertId":"1httvn0g2nj3fae",
            "labels":{
               "request_id":"94ec1661-d472-4ef0-a7bd-d85e22062e4d-aabf4fdf",
               "protocol":"V2_BETA1",
               "type":"dialogflow_response",
               "source":"DIALOGFLOW_CONSOLE"
            },
            "trace":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
            "resource":{
               "labels":{
                  "project_id":"entuber"
               },
               "type":"global"
            },
            "textPayload":{
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
               "result":{
                  "resolved_query":"hello",
                  "contexts":{
                     "parameters":{
                        "fields":{
                           "key":"no-match",
                           "value":{
                              "number_value":0
                           }
                        }
                     },
                     "lifespan":1,
                     "name":"__system_counters__"
                  },
                  "score":1,
                  "action_incomplete":true,
                  "fulfillment":{
                     "messages":{
                        "speech":{
                           "string_value":"What is the name?"
                        },
                        "type":{
                           "number_value":0
                        }
                     },
                     "speech":"What is the name?"
                  },
                  "action":"input.welcome",
                  "metadata":{
                     "is_fallback_intent":false,
                     "intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
                     "webhook_for_slot_filling_used":false,
                     "webhook_used":false,
                     "intent_name":"Default Welcome Intent"
                  },
                  "parameters":{
                     "fields":{
                        "key":"name",
                        "value":{
                           "string_value":""
                        }
                     }
                  },
                  "source":"agent"
               },
               "id":"94ec1661-d472-4ef0-a7bd-d85e22062e4d-aabf4fdf",
               "timestamp":"2020-11-16T06:29:01.596Z",
               "lang":"en"
            },
            "receiveTimestamp":"2020-11-16T06:29:01.64859801Z"
         },
         {
            "severity":"INFO",
            "receiveTimestamp":"2020-11-16T06:29:07.676213264Z",
            "resource":{
               "type":"global",
               "labels":{
                  "project_id":"entuber"
               }
            },
            "insertId":"13ojz2yg2npq0nk",
            "labels":{
               "source":"DIALOGFLOW_CONSOLE",
               "type":"dialogflow_response",
               "request_id":"896b6d41-fe8b-4123-ba68-07004435db42-aabf4fdf",
               "protocol":"V2_BETA1"
            },
            "timestamp":"2020-11-16T06:29:07.667Z",
            "logName":"projects/entuber/logs/dialogflow_agent",
            "trace":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
            "textPayload":{
               "status":{
                  "error_type":"success",
                  "code":200
               },
               "timestamp":"2020-11-16T06:29:07.62Z",
               "lang":"en",
               "result":{
                  "contexts":{
                     "lifespan":50,
                     "name":"name",
                     "parameters":{
                        "fields":{
                           "key":"name.original",
                           "value":{
                              "string_value":"tara"
                           }
                        }
                     }
                  },
                  "source":"agent",
                  "resolved_query":"tara",
                  "score":1,
                  "action":"input.welcome",
                  "fulfillment":{
                     "messages":{
                        "lang":"en",
                        "speech":{
                           "string_value":""
                        },
                        "type":{
                           "number_value":0
                        }
                     },
                     "speech":"Can I have your name?"
                  },
                  "parameters":{
                     "fields":{
                        "key":"name",
                        "value":{
                           "string_value":"Tara"
                        }
                     }
                  },
                  "metadata":{
                     "webhook_for_slot_filling_used":false,
                     "is_fallback_intent":false,
                     "intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
                     "intent_name":"Default Welcome Intent",
                     "webhook_used":false
                  }
               },
               "id":"896b6d41-fe8b-4123-ba68-07004435db42-aabf4fdf",
               "session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804"
            },
            "session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804"
         }
      ]
   }
]
[
   {
      "session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
      "timestamp":"2020-11-13T20:57:17.611Z",
      "labels":{
         "request_id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf",
         "type":"dialogflow_response",
         "protocol":"V2_BETA1",
         "source":"DIALOGFLOW_CONSOLE"
      },
      "Thread":[
         {
            "speech":"What is the name?",
            "timestamp":"2020-11-13T20:57:08.552Z",
            "id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf"
         }
      ]
   }
]

我需要为所有
session\u id
值获得如上所述的结果。

尝试解析JSON数据,使用forEach可以循环数组并进行处理,我在下面附上了一个示例代码片段

let json = JSON.parse("<json data>");

json.forEach(function (data) {
  console.log(data);
  //do your stuff here
});
let json=json.parse(“”);
forEach(函数(数据){
控制台日志(数据);
//在这里做你的事
});

您遇到了概念级问题。一个会话可能有多个线程用于单独的请求,因此您需要支持会话请求/线程的一对多关系。因此,我的解决方案与您的示例输出并不完全相同,因为有多个线程,每个线程都有自己的标签:

var输入=[
{
“时间戳”:“2020-11-13T20:57:17.611Z”,
“会话id”:“eed8d600-0438-37d3-dd96-25081a91b90a”,
“电话”:“55555”,
“姓名”:“迈克”,
“线程”:[
{
“文本有效载荷”:{
“时间戳”:“2020-11-13T20:57:08.552Z”,
“id”:“a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf”,
“地位”:{
“错误类型”:“成功”,
“代码”:200
},
“郎”:“恩”,
“会话id”:“eed8d600-0438-37d3-dd96-25081a91b90a”,
“结果”:{
“分数”:1,
“行动不完整”:正确,
“已解决的查询”:“您好”,
“操作”:“输入。欢迎”,
“来源”:“代理人”,
“元数据”:{
“意向\名称”:“默认欢迎意向”,
“webhook_used”:false,
“意图id”:“d06d9b61-eee2-4481-a038-bc97194d611a”,
“是否有退路意图”:错误,
“用于填充插槽的webhook”:false
},
“参数”:{
“字段”:{
“价值”:{
“字符串值”:”
},
“键”:“名称”
}
},
“上下文”:{
“参数”:{
“字段”:{
“密钥”:“不匹配”,
“价值”:{
“数字值”:0
}
}
},
“名称”:“系统计数器”,
“寿命”:1
},
“履行”:{
“信息”:{
“类型”:{
“数字值”:0
},
“讲话”:{
“字符串值”:“名称是什么?”
}
},
“演讲”:“名字叫什么?”
}
}
},
“insertId”:“1p1x1wdfgkwf2a”,
“严重性”:“信息”,
“接收时间戳”:“2020-11-13T20:57:08.592891686Z”,
“跟踪”:“eed8d600-0438-37d3-dd96-25081a91b90a”,
“标签”:{
“请求id”:“a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf”,
“类型”:“dialogflow\u响应”,
“协议”:“V2_BETA1”,
“源”:“DIALOGFLOW_控制台”
},
“时间戳”:“2020-11-13T20:57:08.571Z”,
“logName”:“projects/entuber/logs/dialogflow_agent”,
“资源”:{
“类型”:“全局”,
“标签”:{
“项目id”:“entuber”
}
},
“会话id”:“eed8d600-0438-37d3-dd96-25081a91b90a”
},
{
“时间戳”:“2020-11-13T20:57:11.746Z”,
“标签”:{
“类型”:“dialogflow\u响应”,
“协议”:“V2_BETA1”,
“源”:“DIALOGFLOW_控制台”,
“请求id”:“70b25970-e228-41b9-9898-26d68bb67c13-aabf4fdf”
},
“资源”:{
“标签”:{
“项目id”:“entuber”
},
“类型”:“全局”
},
“logName”:“projects/entuber/logs/dialogflow_agent”,
“接收时间戳”:“2020-11-13T20:57:11.766438485Z”,
“跟踪”:“eed8d600-0438-37d3-dd96-25081a91b90a”,
“严重性”:“信息”,
“会话id”:“eed8d600-0438-37d3-dd96-25081a91b90a”,
“文本有效载荷”:{
“会话id”:“eed8d600-0438-37d3-dd96-25081a91b90a”,
“地位”:{
“代码”:200,
“错误类型”:“成功”
},
“时间戳”:“2020-11-13T20:57:11.728Z”,
“id”:“70b25970-e228-41b9-9898-26d68bb67c13-aabf4fdf”,
“郎”:“恩”,
“结果”:{
“上下文”:{
“寿命”:50岁,
“参数”:{
“字段”:{
“价值”:{
“字符串值”:“sam”
},
“key”:“name.original”
}
},
“名称”:“名称”
},
“操作”:“输入。欢迎”,
“已解决的查询”:“sam”,
“履行”:{
“演讲”:“嗨,我是塔拉。我被修改成告诉你你的账单是什么。问我你现在的账单,我会告诉你你要付多少钱,什么时候付。”