簡體   English   中英

jQuery查詢格式的CSV導出

[英]jq query format csv export

我使用JQ進行腳本重擊,但是不知道如何執行查詢以獲取以下結果:

對話ID(1),參與者ID(1),參與者名稱(1),會話ID(1)對話ID(1),參與者ID(2),參與者名稱(2),會話ID(2)對話ID(1),參與者ID(3),參與者ID( 3),sessionId(3),sessionId(2),participantId(4),participantName(4),sessionId(4)。 的conversationId(N),participantId(N),participantName(N),的sessionId(n)的

我的文件:data.json

{
    "conversations": [
        {
            "conversationId": "cxx-cccc-4444-9999-b11111111",
            "conversationStart": "2016-06-5T00:10:15.412Z",
            "conversationEnd": "2016-06-5T00:11:19.447Z",
            "participants": [
                {
                    "participantId": "2aaaa-1555-4590-99aa-4yyyyyyy",
                    "userId": "91111-7rrrr-4000-aqaa-23232323",
                    "purpose": "user",
                    "sessions": [
                        {
                            "mediaType": "voice",
                            "sessionId": "1111111-aaaa-4009-9000-488888",
                            "ani": "sip:user+localhost.com@localhost",
                            "direction": "outbound",
                            "dnis": "tel:+1111110000",
                            "edgeId": "e3e3e3-4ª4q-4b4b-9792-95959595",
                            "segments": [
                                {
                             "segmentStart": "2016-06-15T00:10:15.412Z",
                             "segmentEnd": "2016-06-15T00:10:10.485Z",
                            "segmentType": "contacting",
                                    "conference": false
                                },
                                {
                             "segmentStart": "2016-06-15T00:10:10.485Z",
                             "segmentEnd": "2016-06-15T00:10:10.522Z",
                              "segmentType": "dialing",
                               "conference": false
                                },
                                {
                              "segmentStart": "2016-06-15T00:20:10.522Z",
                              "segmentEnd": "2016-06-15T00:11:09.436Z",
                              "disconnectType": "client",
                               "segmentType": "interact",
                                "conference": false
                                }
                            ]
                        }
                    ]
                },
                {
                 "participantId": "e9e9e9-d777-4a4a-8989-aeaeaeaeae",
                    "participantName": "Namek, Sayayin",
                    "purpose": "ivr",
                    "sessions": [
                        {
                            "mediaType": "voice",
                           "sessionId": "262626-6000-4cdd-a511-fafafafa",
                           "ani": "sip:goku%localhost.com@localhost",
                           "direction": "inbound",
                          "edgeId": "e3e3e3e3-4abc-4abc-9700-95959595",
                            "remoteNameDisplayable": "Namek, Sayayin",
                            "segments": [
                                {
                              "segmentStart": "2016-06-15T00:10:10.510Z",
                              "segmentEnd": "2016-06-15T00:10:10.521Z",
                              "segmentType": "system",
                                    "conference": false
                                },
                                {
                             "segmentStart": "2016-06-15T00:10:20.521Z",
                             "segmentEnd": "2016-06-15T00:11:39.447Z",
                              "disconnectType": "peer",
                                    "segmentType": "ivr",
                                    "conference": false
                                }
                            ]
                        }
                    ]
                }
            ]
        },
        {
            "conversationId": "09090909-6b60-8888-xxxx-9yyyyyyyy",
            "conversationStart": "2016-06-15T00:11:38.867Z",
            "conversationEnd": "2016-06-15T01:54:55.744Z",
            "participants": [
                {
                    "participantId": "xxxc-cccc1-4123-7777-343434343e",
                    "userId": "9qwer-7zxc-40df-aghj-2323232323",
                    "purpose": "user",
                    "sessions": [
                        {
                            "mediaType": "voice",
                            "sessionId": "101010-0faz-4xxx-yyyy-4419441",
                            "ani": "sip:goku+localhost.com@localhost",
                            "direction": "outbound",
                            "dnis": "tel:+11112222333",
                            "edgeId": "nenene1-qwer-tyui-9000-9595gggh",
                            "segments": [
                               {
                              "segmentStart": "2016-06-15T00:11:18.867Z",
                              "segmentEnd": "2016-06-15T00:11:42.637Z",
                              "segmentType": "contacting",
                                "conference": false
                                }
                                ]
                        } ]
                } ]
        } ]
}

我的查詢jq:

jq。 '{conversationId:.conversations []。conversationId,參與者ID:.conversations []。participants []。participantId,participantName:.conversations []。participants []。participantName} | 加入(”,”)'

但是字段對話ID和參與者名稱重復了幾次...

使用您的輸入,以下過濾器:

.conversations[]
| [.conversationId]
  + (.participants[] | [.participantId, .participantName])

生產:

[
  "cxx-cccc-4444-9999-b11111111",
  "2aaaa-1555-4590-99aa-4yyyyyyy",
  null
]
[
  "cxx-cccc-4444-9999-b11111111",
  "e9e9e9-d777-4a4a-8989-aeaeaeaeae",
  "Namek, Sayayin"
]
[
  "09090909-6b60-8888-xxxx-9yyyyyyyy",
  "xxxc-cccc1-4123-7777-343434343e",
  null
]

變種

請注意,上述過濾器不使用任何jq變量。 有時介紹它們會有所幫助,因此可能需要以下變體:

.conversations[]
| (.participants | range(0;length)) as $j
| [.conversationId]
  + (.participants[$j] | [.participantId, .participantName])

在jq手冊的幫助下,您應該可以從這里獲取它。

附錄

ParticipantId(1),的sessionId(1),mediaType的(1),的sessionId(1),ANI(1),DNIS(1)

我不太確定您為什么要兩次使用sessionsId ,但是以下內容與您的第二個請求相對應:

.conversations[].participants[]
| [.participantId] +
   (.sessions[] | [.sessionId, .mediaType, .sessionId, .ani, .dnis])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM