I have the JSON data below. I need the JSON to split and form a new JSON data object. I’m new to this and am struggling to get a way to solve this.
below JSON data:
JavaScript
x
627
627
1
[
2
{
3
"timestamp":"2020-11-13T20:57:17.611Z",
4
"session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
5
"Telephone":"555555555",
6
"Name":"Mike",
7
"Thread":[
8
{
9
"textPayload":{
10
"timestamp":"2020-11-13T20:57:08.552Z",
11
"id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf",
12
"status":{
13
"error_type":"success",
14
"code":200
15
},
16
"lang":"en",
17
"session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
18
"result":{
19
"score":1,
20
"action_incomplete":true,
21
"resolved_query":"hi",
22
"action":"input.welcome",
23
"source":"agent",
24
"metadata":{
25
"intent_name":"Default Welcome Intent",
26
"webhook_used":false,
27
"intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
28
"is_fallback_intent":false,
29
"webhook_for_slot_filling_used":false
30
},
31
"parameters":{
32
"fields":{
33
"value":{
34
"string_value":""
35
},
36
"key":"name"
37
}
38
},
39
"contexts":{
40
"parameters":{
41
"fields":{
42
"key":"no-match",
43
"value":{
44
"number_value":0
45
}
46
}
47
},
48
"name":"__system_counters__",
49
"lifespan":1
50
},
51
"fulfillment":{
52
"messages":{
53
"type":{
54
"number_value":0
55
},
56
"speech":{
57
"string_value":"What is the name?"
58
}
59
},
60
"speech":"What is the name?"
61
}
62
}
63
},
64
"insertId":"1p1x1wdfgkwf2a",
65
"severity":"INFO",
66
"receiveTimestamp":"2020-11-13T20:57:08.592891686Z",
67
"trace":"eed8d600-0438-37d3-dd96-25081a91b90a",
68
"labels":{
69
"request_id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf",
70
"type":"dialogflow_response",
71
"protocol":"V2_BETA1",
72
"source":"DIALOGFLOW_CONSOLE"
73
},
74
"timestamp":"2020-11-13T20:57:08.571Z",
75
"logName":"projects/entuber/logs/dialogflow_agent",
76
"resource":{
77
"type":"global",
78
"labels":{
79
"project_id":"entuber"
80
}
81
},
82
"session_id":"eed8d600-0438-37d3-dd96-25081a91b90a"
83
},
84
{
85
"timestamp":"2020-11-13T20:57:11.746Z",
86
"labels":{
87
"type":"dialogflow_response",
88
"protocol":"V2_BETA1",
89
"source":"DIALOGFLOW_CONSOLE",
90
"request_id":"70b25970-e228-41b9-9898-26d68bb67c13-aabf4fdf"
91
},
92
"resource":{
93
"labels":{
94
"project_id":"entuber"
95
},
96
"type":"global"
97
},
98
"logName":"projects/entuber/logs/dialogflow_agent",
99
"receiveTimestamp":"2020-11-13T20:57:11.766438485Z",
100
"trace":"eed8d600-0438-37d3-dd96-25081a91b90a",
101
"severity":"INFO",
102
"session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
103
"textPayload":{
104
"session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
105
"status":{
106
"code":200,
107
"error_type":"success"
108
},
109
"timestamp":"2020-11-13T20:57:11.728Z",
110
"id":"70b25970-e228-41b9-9898-26d68bb67c13-aabf4fdf",
111
"lang":"en",
112
"result":{
113
"contexts":{
114
"lifespan":50,
115
"parameters":{
116
"fields":{
117
"value":{
118
"string_value":"sam"
119
},
120
"key":"name.original"
121
}
122
},
123
"name":"name"
124
},
125
"action":"input.welcome",
126
"resolved_query":"sam",
127
"fulfillment":{
128
"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.",
129
"messages":{
130
"speech":{
131
"string_value":""
132
},
133
"lang":"en",
134
"type":{
135
"number_value":0
136
}
137
}
138
},
139
"parameters":{
140
"fields":{
141
"key":"name",
142
"value":{
143
"string_value":"Sam"
144
}
145
}
146
},
147
"metadata":{
148
"intent_name":"Default Welcome Intent",
149
"is_fallback_intent":false,
150
"intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
151
"webhook_for_slot_filling_used":false,
152
"webhook_used":false
153
},
154
"source":"agent",
155
"score":1
156
}
157
},
158
"insertId":"1orjxuhfg78gle"
159
},
160
]
161
},
162
{
163
"session_id":"TestTaraSession",
164
"timestamp":"2020-11-16T06:17:37.536Z",
165
"Thread":[
166
{
167
"resource":{
168
"type":"global",
169
"labels":{
170
"project_id":"entuber"
171
}
172
},
173
"insertId":"ftk71rg38zc3de",
174
"trace":"TestTaraSession",
175
"logName":"projects/entuber/logs/dialogflow_agent",
176
"labels":{
177
"type":"dialogflow_response",
178
"request_id":"1fd35e1d-7830-4606-937d-b8685dde0129-aabf4fdf",
179
"protocol":"V2_BETA1"
180
},
181
"severity":"INFO",
182
"timestamp":"2020-11-16T06:16:50.421Z",
183
"session_id":"TestTaraSession",
184
"receiveTimestamp":"2020-11-16T06:16:50.45315191Z",
185
"textPayload":{
186
"status":{
187
"error_type":"success",
188
"code":200
189
},
190
"id":"1fd35e1d-7830-4606-937d-b8685dde0129-aabf4fdf",
191
"lang":"en",
192
"session_id":"TestTaraSession",
193
"result":{
194
"score":1,
195
"parameters":{
196
"fields":{
197
"value":{
198
"string_value":""
199
},
200
"key":"name"
201
}
202
},
203
"metadata":{
204
"intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
205
"is_fallback_intent":false,
206
"webhook_used":false,
207
"intent_name":"Default Welcome Intent",
208
"webhook_for_slot_filling_used":false
209
},
210
"action":"input.welcome",
211
"contexts":{
212
"lifespan":1,
213
"name":"__system_counters__",
214
"parameters":{
215
"fields":{
216
"value":{
217
"number_value":0
218
},
219
"key":"no-match"
220
}
221
}
222
},
223
"action_incomplete":true,
224
"fulfillment":{
225
"messages":{
226
"type":{
227
"number_value":0
228
},
229
"speech":{
230
"string_value":"What is the name?"
231
}
232
},
233
"speech":"What is the name?"
234
},
235
"source":"agent",
236
"resolved_query":"WELCOME"
237
},
238
"timestamp":"2020-11-16T06:16:50.408Z"
239
}
240
},
241
{
242
"session_id":"TestTaraSession",
243
"timestamp":"2020-11-16T06:17:08.746Z",
244
"insertId":"1ggf79rg3d2lksr",
245
"labels":{
246
"protocol":"V2_BETA1",
247
"type":"dialogflow_response",
248
"request_id":"ff18d72b-5fbc-4e44-a52d-f987d0d59d9d-aabf4fdf"
249
},
250
"logName":"projects/entuber/logs/dialogflow_agent",
251
"receiveTimestamp":"2020-11-16T06:17:08.756453598Z",
252
"trace":"TestTaraSession",
253
"textPayload":{
254
"session_id":"TestTaraSession",
255
"lang":"en",
256
"result":{
257
"contexts":{
258
"parameters":{
259
"fields":{
260
"value":{
261
"string_value":"Tara"
262
},
263
"key":"name.original"
264
}
265
},
266
"lifespan":50,
267
"name":"name"
268
},
269
"metadata":{
270
"intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
271
"is_fallback_intent":false,
272
"webhook_used":false,
273
"webhook_for_slot_filling_used":false,
274
"intent_name":"Default Welcome Intent"
275
},
276
"parameters":{
277
"fields":{
278
"value":{
279
"string_value":"Tara"
280
},
281
"key":"name"
282
}
283
},
284
"action":"input.welcome",
285
"source":"agent",
286
"score":1,
287
"fulfillment":{
288
"messages":{
289
"lang":"en",
290
"speech":{
291
"string_value":""
292
},
293
"type":{
294
"number_value":0
295
}
296
},
297
"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."
298
},
299
"resolved_query":"Tara"
300
},
301
"timestamp":"2020-11-16T06:17:08.742Z",
302
"status":{
303
"error_type":"success",
304
"code":200
305
},
306
"id":"ff18d72b-5fbc-4e44-a52d-f987d0d59d9d-aabf4fdf"
307
},
308
"severity":"INFO",
309
"resource":{
310
"labels":{
311
"project_id":"entuber"
312
},
313
"type":"global"
314
}
315
},
316
{
317
"trace":"TestTaraSession",
318
"receiveTimestamp":"2020-11-16T06:17:17.973535789Z",
319
"logName":"projects/entuber/logs/dialogflow_agent",
320
"textPayload":{
321
"lang":"en",
322
"timestamp":"2020-11-16T06:17:17.943Z",
323
"result":{
324
"score":0.686966,
325
"parameters":{
326
"fields":{
327
"value":{
328
"string_value":""
329
},
330
"key":"accountNo"
331
}
332
},
333
"action":"com.tara.bills",
334
"metadata":{
335
"intent_id":"5ff968ab-3646-4abe-ae7e-93203997e5fb",
336
"webhook_used":true,
337
"webhook_for_slot_filling_used":false,
338
"intent_name":"Read Bill",
339
"is_fallback_intent":false
340
},
341
"resolved_query":"Bill details",
342
"action_incomplete":true,
343
"source":"agent",
344
"fulfillment":{
345
"messages":{
346
"speech":{
347
"string_value":"What is your account number?"
348
},
349
"type":{
350
"number_value":0
351
}
352
},
353
"speech":"What is your account number?"
354
},
355
"contexts":{
356
"parameters":{
357
"fields":{
358
"key":"no-match",
359
"value":{
360
"number_value":0
361
}
362
}
363
},
364
"name":"__system_counters__",
365
"lifespan":1
366
}
367
},
368
"id":"ab128f85-0044-42ba-ae8a-c77d0905d972-aabf4fdf",
369
"status":{
370
"error_type":"success",
371
"code":200
372
},
373
"session_id":"TestTaraSession"
374
},
375
"severity":"INFO",
376
"session_id":"TestTaraSession",
377
"resource":{
378
"labels":{
379
"project_id":"entuber"
380
},
381
"type":"global"
382
},
383
"timestamp":"2020-11-16T06:17:17.965Z",
384
"insertId":"dc02v6g3eo2vya",
385
"labels":{
386
"type":"dialogflow_response",
387
"protocol":"V2_BETA1",
388
"request_id":"ab128f85-0044-42ba-ae8a-c77d0905d972-aabf4fdf"
389
}
390
},
391
{
392
"textPayload":{
393
"session_id":"TestTaraSession",
394
"status":{
395
"error_type":"success",
396
"code":200
397
},
398
"result":{
399
"metadata":{
400
"webhook_used":false,
401
"intent_name":"Read Bill",
402
"webhook_response_time":3334,
403
"intent_id":"5ff968ab-3646-4abe-ae7e-93203997e5fb",
404
"is_fallback_intent":false,
405
"webhook_for_slot_filling_used":false
406
},
407
"contexts":{
408
"name":"defaultwelcomeintent-followup",
409
"lifespan":1,
410
"parameters":{
411
"fields":{
412
"value":{
413
"string_value":"Tara"
414
},
415
"key":"name.original"
416
}
417
}
418
},
419
"source":"agent",
420
"action":"com.tara.bills",
421
"fulfillment":{
422
"speech":"Your current bill of $2927.62 is due on 10/19/2020.",
423
"messages":{
424
"speech":{
425
"string_value":"Your current bill of $2927.62 is due on 10/19/2020."
426
},
427
"type":{
428
"number_value":0
429
}
430
}
431
},
432
"score":1,
433
"parameters":{
434
"fields":{
435
"value":{
436
"number_value":21012875
437
},
438
"key":"accountNo"
439
}
440
},
441
"resolved_query":21012875
442
},
443
"lang":"en",
444
"id":"1d3df1d2-1753-48fc-948e-7fc91473d055-aabf4fdf",
445
"timestamp":"2020-11-16T06:17:34.184Z"
446
},
447
"insertId":"1def6i1g15mb48l",
448
"labels":{
449
"protocol":"V2_BETA1",
450
"request_id":"1d3df1d2-1753-48fc-948e-7fc91473d055-aabf4fdf",
451
"type":"dialogflow_response"
452
},
453
"receiveTimestamp":"2020-11-16T06:17:37.548546643Z",
454
"timestamp":"2020-11-16T06:17:37.536Z",
455
"severity":"INFO",
456
"resource":{
457
"type":"global",
458
"labels":{
459
"project_id":"entuber"
460
}
461
},
462
"session_id":"TestTaraSession",
463
"trace":"TestTaraSession",
464
"logName":"projects/entuber/logs/dialogflow_agent"
465
}
466
]
467
},
468
{
469
"timestamp":"2020-11-16T06:29:14.564Z",
470
"session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
471
"Thread":[
472
{
473
"timestamp":"2020-11-16T06:29:01.638Z",
474
"session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
475
"logName":"projects/entuber/logs/dialogflow_agent",
476
"severity":"INFO",
477
"insertId":"1httvn0g2nj3fae",
478
"labels":{
479
"request_id":"94ec1661-d472-4ef0-a7bd-d85e22062e4d-aabf4fdf",
480
"protocol":"V2_BETA1",
481
"type":"dialogflow_response",
482
"source":"DIALOGFLOW_CONSOLE"
483
},
484
"trace":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
485
"resource":{
486
"labels":{
487
"project_id":"entuber"
488
},
489
"type":"global"
490
},
491
"textPayload":{
492
"status":{
493
"error_type":"success",
494
"code":200
495
},
496
"session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
497
"result":{
498
"resolved_query":"hello",
499
"contexts":{
500
"parameters":{
501
"fields":{
502
"key":"no-match",
503
"value":{
504
"number_value":0
505
}
506
}
507
},
508
"lifespan":1,
509
"name":"__system_counters__"
510
},
511
"score":1,
512
"action_incomplete":true,
513
"fulfillment":{
514
"messages":{
515
"speech":{
516
"string_value":"What is the name?"
517
},
518
"type":{
519
"number_value":0
520
}
521
},
522
"speech":"What is the name?"
523
},
524
"action":"input.welcome",
525
"metadata":{
526
"is_fallback_intent":false,
527
"intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
528
"webhook_for_slot_filling_used":false,
529
"webhook_used":false,
530
"intent_name":"Default Welcome Intent"
531
},
532
"parameters":{
533
"fields":{
534
"key":"name",
535
"value":{
536
"string_value":""
537
}
538
}
539
},
540
"source":"agent"
541
},
542
"id":"94ec1661-d472-4ef0-a7bd-d85e22062e4d-aabf4fdf",
543
"timestamp":"2020-11-16T06:29:01.596Z",
544
"lang":"en"
545
},
546
"receiveTimestamp":"2020-11-16T06:29:01.64859801Z"
547
},
548
{
549
"severity":"INFO",
550
"receiveTimestamp":"2020-11-16T06:29:07.676213264Z",
551
"resource":{
552
"type":"global",
553
"labels":{
554
"project_id":"entuber"
555
}
556
},
557
"insertId":"13ojz2yg2npq0nk",
558
"labels":{
559
"source":"DIALOGFLOW_CONSOLE",
560
"type":"dialogflow_response",
561
"request_id":"896b6d41-fe8b-4123-ba68-07004435db42-aabf4fdf",
562
"protocol":"V2_BETA1"
563
},
564
"timestamp":"2020-11-16T06:29:07.667Z",
565
"logName":"projects/entuber/logs/dialogflow_agent",
566
"trace":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
567
"textPayload":{
568
"status":{
569
"error_type":"success",
570
"code":200
571
},
572
"timestamp":"2020-11-16T06:29:07.62Z",
573
"lang":"en",
574
"result":{
575
"contexts":{
576
"lifespan":50,
577
"name":"name",
578
"parameters":{
579
"fields":{
580
"key":"name.original",
581
"value":{
582
"string_value":"tara"
583
}
584
}
585
}
586
},
587
"source":"agent",
588
"resolved_query":"tara",
589
"score":1,
590
"action":"input.welcome",
591
"fulfillment":{
592
"messages":{
593
"lang":"en",
594
"speech":{
595
"string_value":""
596
},
597
"type":{
598
"number_value":0
599
}
600
},
601
"speech":"Can I have your name?"
602
},
603
"parameters":{
604
"fields":{
605
"key":"name",
606
"value":{
607
"string_value":"Tara"
608
}
609
}
610
},
611
"metadata":{
612
"webhook_for_slot_filling_used":false,
613
"is_fallback_intent":false,
614
"intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
615
"intent_name":"Default Welcome Intent",
616
"webhook_used":false
617
}
618
},
619
"id":"896b6d41-fe8b-4123-ba68-07004435db42-aabf4fdf",
620
"session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804"
621
},
622
"session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804"
623
}
624
]
625
}
626
]
627
This has to be done for all the session_id
values in the input JSON data.
It has to form all the JSON data to iterate and show in another HTML.
I’m confused here and aim to get the following:
Sample output:
JavaScript
1
20
20
1
[
2
{
3
"session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
4
"timestamp":"2020-11-13T20:57:17.611Z",
5
"labels":{
6
"request_id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf",
7
"type":"dialogflow_response",
8
"protocol":"V2_BETA1",
9
"source":"DIALOGFLOW_CONSOLE"
10
},
11
"Thread":[
12
{
13
"speech":"What is the name?",
14
"timestamp":"2020-11-13T20:57:08.552Z",
15
"id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf"
16
}
17
]
18
}
19
]
20
I need to get a result like above for all session_id
values.
Advertisement
Answer
You have a concept-level problem. A session may have multiple threads for separate requests and therefore you need to support a one-to-many relationship for session-request/thread. So, my solution is not exactly looking like your sample output, because there are multiple threads, each having their own label:
JavaScript
1
645
645
1
var input = [
2
{
3
"timestamp":"2020-11-13T20:57:17.611Z",
4
"session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
5
"Telephone":"555555555",
6
"Name":"Mike",
7
"Thread":[
8
{
9
"textPayload":{
10
"timestamp":"2020-11-13T20:57:08.552Z",
11
"id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf",
12
"status":{
13
"error_type":"success",
14
"code":200
15
},
16
"lang":"en",
17
"session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
18
"result":{
19
"score":1,
20
"action_incomplete":true,
21
"resolved_query":"hi",
22
"action":"input.welcome",
23
"source":"agent",
24
"metadata":{
25
"intent_name":"Default Welcome Intent",
26
"webhook_used":false,
27
"intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
28
"is_fallback_intent":false,
29
"webhook_for_slot_filling_used":false
30
},
31
"parameters":{
32
"fields":{
33
"value":{
34
"string_value":""
35
},
36
"key":"name"
37
}
38
},
39
"contexts":{
40
"parameters":{
41
"fields":{
42
"key":"no-match",
43
"value":{
44
"number_value":0
45
}
46
}
47
},
48
"name":"__system_counters__",
49
"lifespan":1
50
},
51
"fulfillment":{
52
"messages":{
53
"type":{
54
"number_value":0
55
},
56
"speech":{
57
"string_value":"What is the name?"
58
}
59
},
60
"speech":"What is the name?"
61
}
62
}
63
},
64
"insertId":"1p1x1wdfgkwf2a",
65
"severity":"INFO",
66
"receiveTimestamp":"2020-11-13T20:57:08.592891686Z",
67
"trace":"eed8d600-0438-37d3-dd96-25081a91b90a",
68
"labels":{
69
"request_id":"a97809e8-3466-4404-947e-4ec89f96878b-aabf4fdf",
70
"type":"dialogflow_response",
71
"protocol":"V2_BETA1",
72
"source":"DIALOGFLOW_CONSOLE"
73
},
74
"timestamp":"2020-11-13T20:57:08.571Z",
75
"logName":"projects/entuber/logs/dialogflow_agent",
76
"resource":{
77
"type":"global",
78
"labels":{
79
"project_id":"entuber"
80
}
81
},
82
"session_id":"eed8d600-0438-37d3-dd96-25081a91b90a"
83
},
84
{
85
"timestamp":"2020-11-13T20:57:11.746Z",
86
"labels":{
87
"type":"dialogflow_response",
88
"protocol":"V2_BETA1",
89
"source":"DIALOGFLOW_CONSOLE",
90
"request_id":"70b25970-e228-41b9-9898-26d68bb67c13-aabf4fdf"
91
},
92
"resource":{
93
"labels":{
94
"project_id":"entuber"
95
},
96
"type":"global"
97
},
98
"logName":"projects/entuber/logs/dialogflow_agent",
99
"receiveTimestamp":"2020-11-13T20:57:11.766438485Z",
100
"trace":"eed8d600-0438-37d3-dd96-25081a91b90a",
101
"severity":"INFO",
102
"session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
103
"textPayload":{
104
"session_id":"eed8d600-0438-37d3-dd96-25081a91b90a",
105
"status":{
106
"code":200,
107
"error_type":"success"
108
},
109
"timestamp":"2020-11-13T20:57:11.728Z",
110
"id":"70b25970-e228-41b9-9898-26d68bb67c13-aabf4fdf",
111
"lang":"en",
112
"result":{
113
"contexts":{
114
"lifespan":50,
115
"parameters":{
116
"fields":{
117
"value":{
118
"string_value":"sam"
119
},
120
"key":"name.original"
121
}
122
},
123
"name":"name"
124
},
125
"action":"input.welcome",
126
"resolved_query":"sam",
127
"fulfillment":{
128
"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.",
129
"messages":{
130
"speech":{
131
"string_value":""
132
},
133
"lang":"en",
134
"type":{
135
"number_value":0
136
}
137
}
138
},
139
"parameters":{
140
"fields":{
141
"key":"name",
142
"value":{
143
"string_value":"Sam"
144
}
145
}
146
},
147
"metadata":{
148
"intent_name":"Default Welcome Intent",
149
"is_fallback_intent":false,
150
"intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
151
"webhook_for_slot_filling_used":false,
152
"webhook_used":false
153
},
154
"source":"agent",
155
"score":1
156
}
157
},
158
"insertId":"1orjxuhfg78gle"
159
},
160
]
161
},
162
{
163
"session_id":"TestTaraSession",
164
"timestamp":"2020-11-16T06:17:37.536Z",
165
"Thread":[
166
{
167
"resource":{
168
"type":"global",
169
"labels":{
170
"project_id":"entuber"
171
}
172
},
173
"insertId":"ftk71rg38zc3de",
174
"trace":"TestTaraSession",
175
"logName":"projects/entuber/logs/dialogflow_agent",
176
"labels":{
177
"type":"dialogflow_response",
178
"request_id":"1fd35e1d-7830-4606-937d-b8685dde0129-aabf4fdf",
179
"protocol":"V2_BETA1"
180
},
181
"severity":"INFO",
182
"timestamp":"2020-11-16T06:16:50.421Z",
183
"session_id":"TestTaraSession",
184
"receiveTimestamp":"2020-11-16T06:16:50.45315191Z",
185
"textPayload":{
186
"status":{
187
"error_type":"success",
188
"code":200
189
},
190
"id":"1fd35e1d-7830-4606-937d-b8685dde0129-aabf4fdf",
191
"lang":"en",
192
"session_id":"TestTaraSession",
193
"result":{
194
"score":1,
195
"parameters":{
196
"fields":{
197
"value":{
198
"string_value":""
199
},
200
"key":"name"
201
}
202
},
203
"metadata":{
204
"intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
205
"is_fallback_intent":false,
206
"webhook_used":false,
207
"intent_name":"Default Welcome Intent",
208
"webhook_for_slot_filling_used":false
209
},
210
"action":"input.welcome",
211
"contexts":{
212
"lifespan":1,
213
"name":"__system_counters__",
214
"parameters":{
215
"fields":{
216
"value":{
217
"number_value":0
218
},
219
"key":"no-match"
220
}
221
}
222
},
223
"action_incomplete":true,
224
"fulfillment":{
225
"messages":{
226
"type":{
227
"number_value":0
228
},
229
"speech":{
230
"string_value":"What is the name?"
231
}
232
},
233
"speech":"What is the name?"
234
},
235
"source":"agent",
236
"resolved_query":"WELCOME"
237
},
238
"timestamp":"2020-11-16T06:16:50.408Z"
239
}
240
},
241
{
242
"session_id":"TestTaraSession",
243
"timestamp":"2020-11-16T06:17:08.746Z",
244
"insertId":"1ggf79rg3d2lksr",
245
"labels":{
246
"protocol":"V2_BETA1",
247
"type":"dialogflow_response",
248
"request_id":"ff18d72b-5fbc-4e44-a52d-f987d0d59d9d-aabf4fdf"
249
},
250
"logName":"projects/entuber/logs/dialogflow_agent",
251
"receiveTimestamp":"2020-11-16T06:17:08.756453598Z",
252
"trace":"TestTaraSession",
253
"textPayload":{
254
"session_id":"TestTaraSession",
255
"lang":"en",
256
"result":{
257
"contexts":{
258
"parameters":{
259
"fields":{
260
"value":{
261
"string_value":"Tara"
262
},
263
"key":"name.original"
264
}
265
},
266
"lifespan":50,
267
"name":"name"
268
},
269
"metadata":{
270
"intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
271
"is_fallback_intent":false,
272
"webhook_used":false,
273
"webhook_for_slot_filling_used":false,
274
"intent_name":"Default Welcome Intent"
275
},
276
"parameters":{
277
"fields":{
278
"value":{
279
"string_value":"Tara"
280
},
281
"key":"name"
282
}
283
},
284
"action":"input.welcome",
285
"source":"agent",
286
"score":1,
287
"fulfillment":{
288
"messages":{
289
"lang":"en",
290
"speech":{
291
"string_value":""
292
},
293
"type":{
294
"number_value":0
295
}
296
},
297
"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."
298
},
299
"resolved_query":"Tara"
300
},
301
"timestamp":"2020-11-16T06:17:08.742Z",
302
"status":{
303
"error_type":"success",
304
"code":200
305
},
306
"id":"ff18d72b-5fbc-4e44-a52d-f987d0d59d9d-aabf4fdf"
307
},
308
"severity":"INFO",
309
"resource":{
310
"labels":{
311
"project_id":"entuber"
312
},
313
"type":"global"
314
}
315
},
316
{
317
"trace":"TestTaraSession",
318
"receiveTimestamp":"2020-11-16T06:17:17.973535789Z",
319
"logName":"projects/entuber/logs/dialogflow_agent",
320
"textPayload":{
321
"lang":"en",
322
"timestamp":"2020-11-16T06:17:17.943Z",
323
"result":{
324
"score":0.686966,
325
"parameters":{
326
"fields":{
327
"value":{
328
"string_value":""
329
},
330
"key":"accountNo"
331
}
332
},
333
"action":"com.tara.bills",
334
"metadata":{
335
"intent_id":"5ff968ab-3646-4abe-ae7e-93203997e5fb",
336
"webhook_used":true,
337
"webhook_for_slot_filling_used":false,
338
"intent_name":"Read Bill",
339
"is_fallback_intent":false
340
},
341
"resolved_query":"Bill details",
342
"action_incomplete":true,
343
"source":"agent",
344
"fulfillment":{
345
"messages":{
346
"speech":{
347
"string_value":"What is your account number?"
348
},
349
"type":{
350
"number_value":0
351
}
352
},
353
"speech":"What is your account number?"
354
},
355
"contexts":{
356
"parameters":{
357
"fields":{
358
"key":"no-match",
359
"value":{
360
"number_value":0
361
}
362
}
363
},
364
"name":"__system_counters__",
365
"lifespan":1
366
}
367
},
368
"id":"ab128f85-0044-42ba-ae8a-c77d0905d972-aabf4fdf",
369
"status":{
370
"error_type":"success",
371
"code":200
372
},
373
"session_id":"TestTaraSession"
374
},
375
"severity":"INFO",
376
"session_id":"TestTaraSession",
377
"resource":{
378
"labels":{
379
"project_id":"entuber"
380
},
381
"type":"global"
382
},
383
"timestamp":"2020-11-16T06:17:17.965Z",
384
"insertId":"dc02v6g3eo2vya",
385
"labels":{
386
"type":"dialogflow_response",
387
"protocol":"V2_BETA1",
388
"request_id":"ab128f85-0044-42ba-ae8a-c77d0905d972-aabf4fdf"
389
}
390
},
391
{
392
"textPayload":{
393
"session_id":"TestTaraSession",
394
"status":{
395
"error_type":"success",
396
"code":200
397
},
398
"result":{
399
"metadata":{
400
"webhook_used":false,
401
"intent_name":"Read Bill",
402
"webhook_response_time":3334,
403
"intent_id":"5ff968ab-3646-4abe-ae7e-93203997e5fb",
404
"is_fallback_intent":false,
405
"webhook_for_slot_filling_used":false
406
},
407
"contexts":{
408
"name":"defaultwelcomeintent-followup",
409
"lifespan":1,
410
"parameters":{
411
"fields":{
412
"value":{
413
"string_value":"Tara"
414
},
415
"key":"name.original"
416
}
417
}
418
},
419
"source":"agent",
420
"action":"com.tara.bills",
421
"fulfillment":{
422
"speech":"Your current bill of $2927.62 is due on 10/19/2020.",
423
"messages":{
424
"speech":{
425
"string_value":"Your current bill of $2927.62 is due on 10/19/2020."
426
},
427
"type":{
428
"number_value":0
429
}
430
}
431
},
432
"score":1,
433
"parameters":{
434
"fields":{
435
"value":{
436
"number_value":21012875
437
},
438
"key":"accountNo"
439
}
440
},
441
"resolved_query":21012875
442
},
443
"lang":"en",
444
"id":"1d3df1d2-1753-48fc-948e-7fc91473d055-aabf4fdf",
445
"timestamp":"2020-11-16T06:17:34.184Z"
446
},
447
"insertId":"1def6i1g15mb48l",
448
"labels":{
449
"protocol":"V2_BETA1",
450
"request_id":"1d3df1d2-1753-48fc-948e-7fc91473d055-aabf4fdf",
451
"type":"dialogflow_response"
452
},
453
"receiveTimestamp":"2020-11-16T06:17:37.548546643Z",
454
"timestamp":"2020-11-16T06:17:37.536Z",
455
"severity":"INFO",
456
"resource":{
457
"type":"global",
458
"labels":{
459
"project_id":"entuber"
460
}
461
},
462
"session_id":"TestTaraSession",
463
"trace":"TestTaraSession",
464
"logName":"projects/entuber/logs/dialogflow_agent"
465
}
466
]
467
},
468
{
469
"timestamp":"2020-11-16T06:29:14.564Z",
470
"session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
471
"Thread":[
472
{
473
"timestamp":"2020-11-16T06:29:01.638Z",
474
"session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
475
"logName":"projects/entuber/logs/dialogflow_agent",
476
"severity":"INFO",
477
"insertId":"1httvn0g2nj3fae",
478
"labels":{
479
"request_id":"94ec1661-d472-4ef0-a7bd-d85e22062e4d-aabf4fdf",
480
"protocol":"V2_BETA1",
481
"type":"dialogflow_response",
482
"source":"DIALOGFLOW_CONSOLE"
483
},
484
"trace":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
485
"resource":{
486
"labels":{
487
"project_id":"entuber"
488
},
489
"type":"global"
490
},
491
"textPayload":{
492
"status":{
493
"error_type":"success",
494
"code":200
495
},
496
"session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
497
"result":{
498
"resolved_query":"hello",
499
"contexts":{
500
"parameters":{
501
"fields":{
502
"key":"no-match",
503
"value":{
504
"number_value":0
505
}
506
}
507
},
508
"lifespan":1,
509
"name":"__system_counters__"
510
},
511
"score":1,
512
"action_incomplete":true,
513
"fulfillment":{
514
"messages":{
515
"speech":{
516
"string_value":"What is the name?"
517
},
518
"type":{
519
"number_value":0
520
}
521
},
522
"speech":"What is the name?"
523
},
524
"action":"input.welcome",
525
"metadata":{
526
"is_fallback_intent":false,
527
"intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
528
"webhook_for_slot_filling_used":false,
529
"webhook_used":false,
530
"intent_name":"Default Welcome Intent"
531
},
532
"parameters":{
533
"fields":{
534
"key":"name",
535
"value":{
536
"string_value":""
537
}
538
}
539
},
540
"source":"agent"
541
},
542
"id":"94ec1661-d472-4ef0-a7bd-d85e22062e4d-aabf4fdf",
543
"timestamp":"2020-11-16T06:29:01.596Z",
544
"lang":"en"
545
},
546
"receiveTimestamp":"2020-11-16T06:29:01.64859801Z"
547
},
548
{
549
"severity":"INFO",
550
"receiveTimestamp":"2020-11-16T06:29:07.676213264Z",
551
"resource":{
552
"type":"global",
553
"labels":{
554
"project_id":"entuber"
555
}
556
},
557
"insertId":"13ojz2yg2npq0nk",
558
"labels":{
559
"source":"DIALOGFLOW_CONSOLE",
560
"type":"dialogflow_response",
561
"request_id":"896b6d41-fe8b-4123-ba68-07004435db42-aabf4fdf",
562
"protocol":"V2_BETA1"
563
},
564
"timestamp":"2020-11-16T06:29:07.667Z",
565
"logName":"projects/entuber/logs/dialogflow_agent",
566
"trace":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804",
567
"textPayload":{
568
"status":{
569
"error_type":"success",
570
"code":200
571
},
572
"timestamp":"2020-11-16T06:29:07.62Z",
573
"lang":"en",
574
"result":{
575
"contexts":{
576
"lifespan":50,
577
"name":"name",
578
"parameters":{
579
"fields":{
580
"key":"name.original",
581
"value":{
582
"string_value":"tara"
583
}
584
}
585
}
586
},
587
"source":"agent",
588
"resolved_query":"tara",
589
"score":1,
590
"action":"input.welcome",
591
"fulfillment":{
592
"messages":{
593
"lang":"en",
594
"speech":{
595
"string_value":""
596
},
597
"type":{
598
"number_value":0
599
}
600
},
601
"speech":"Can I have your name?"
602
},
603
"parameters":{
604
"fields":{
605
"key":"name",
606
"value":{
607
"string_value":"Tara"
608
}
609
}
610
},
611
"metadata":{
612
"webhook_for_slot_filling_used":false,
613
"is_fallback_intent":false,
614
"intent_id":"d06d9b61-eee2-4481-a038-bc97194d611a",
615
"intent_name":"Default Welcome Intent",
616
"webhook_used":false
617
}
618
},
619
"id":"896b6d41-fe8b-4123-ba68-07004435db42-aabf4fdf",
620
"session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804"
621
},
622
"session_id":"9b86412b-ec2d-39c0-7cbc-7a44a74a8804"
623
}
624
]
625
}
626
];
627
628
var output = [];
629
630
for (let key in input) {
631
var result = {
632
session_id: input[key].session_id,
633
timestamp: input[key].timestamp,
634
Thread: []
635
};
636
for (let th of input[key].Thread) result.Thread.push({
637
labels: th.labels,
638
speech: th.textPayload.result.fulfillment.speech,
639
timestamp: th.textPayload.timestamp,
640
id: th.textPayload.id
641
});
642
output.push(result);
643
};
644
645
console.log(output);