使用 `curl` 和 `jq` 测试 RESTful API - `jq` 基础

A json file for testingview raw
1
{"status":200,"errorMsg":"Operation OK!","data":[{"id":10202,"idolId":158,"activityId":1026,"active":1,"title":"可以","introduce":" ","firstFrame":"http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/e07821a403a442bfa27e1bcd037c50a5/1000.jpg","thumbnail":"http://upload.groupy.vip/video_thumbnail/2068135D-3AC8-4BB7-B982-48176A42DED2.jpg","thumbnailWidth":360,"thumbnailHeight":480,"videoWidth":360,"videoHeight":480,"publicType":0,"duration":3,"publishTime":1519804082000,"activity":{"id":1026,"title":"麦萌 x Groupy","description":"1位のアイドルはユーザー数が1000万人超えの中国最大級アフレコアプリ「麦萌対手戏」に声で出演!推しメンを応援してね~♪","rankingType":1,"position":1,"goal":"ランキング上位1名のアイドル","img":"http://image.groupy.vip/acticity_banner/activity-maimeng.jpg","tag":"Groupyx麦萌","actionInfo":"http://activity.groupy.cn/maimeng/index.html?activityId\u003d1026","shareLink":"http://share.groupy.cn/html/activity_maimeng/index.html?activityId\u003d1026","shareTitle":"【#Groupyx麦萌コラボ 】","shareDesc":"上位1名は中国最大級アフレコアプリ「麦萌対手戏」に声で出演!応援しよう!","startTime":1506787201000,"endTime":1525190399000,"type":2,"state":"inProgress","rankingList":[],"isActivityEnded":false},"activityTag":"Groupyx麦萌","featureMask":0,"videoItemList":[],"postList":[],"readCount":3,"popularity":1393369,"gcoin":696674,"postCount":0,"giftCount":0,"idol":{"id":158,"userType":"idol","gender":"unknown","nickname":"妈妈说名字长一点可以看到一般人看不到的bug😁g","avatar":"http://upload.groupy.vip/avatar/F7357D2B-C304-43EB-9796-9824B3E14E2A.jpg","sign":"","introduce":"","imgs":"","levelPlatform":0,"dateOfBirth":776962800000,"bloodType":"Unknown","organizationId":3,"fansNums":0,"followedIdol":false},"videoGifts":[{"fansId":20295,"nickname":"抖腿ing,名字要很长才不会抖输别人","avatar":"http://upload.groupy.vip/avatar/14584F09-75CB-4531-A841-7ACF9CEF5BCC.jpg","giftId":5,"giftNums":1,"giftName":"熊","giftImg":"http://image.groupy.vip/gifts/gift_bear.png","gprice":122,"levelPlatform":103},{"fansId":20295,"nickname":"抖腿ing,名字要很长才不会抖输别人","avatar":"http://upload.groupy.vip/avatar/14584F09-75CB-4531-A841-7ACF9CEF5BCC.jpg","giftId":14,"giftNums":2,"giftName":"超级拉面","giftImg":"http://image.groupy.vip/gifts/gift_noodles.png","gprice":538,"levelPlatform":103},{"fansId":20295,"nickname":"抖腿ing,名字要很长才不会抖输别人","avatar":"http://upload.groupy.vip/avatar/14584F09-75CB-4531-A841-7ACF9CEF5BCC.jpg","giftId":8,"giftNums":1,"giftName":"迪士尼城堡","giftImg":"http://image.groupy.vip/gifts/gift_castle.png","gprice":2929,"levelPlatform":103},{"fansId":20295,"nickname":"抖腿ing,名字要很长才不会抖输别人","avatar":"http://upload.groupy.vip/avatar/14584F09-75CB-4531-A841-7ACF9CEF5BCC.jpg","giftId":12,"giftNums":6,"giftName":"红叶林","giftImg":"http://image.groupy.vip/gifts/gift_maple.png","gprice":41928,"levelPlatform":103},{"fansId":20295,"nickname":"抖腿ing,名字要很长才不会抖输别人","avatar":"http://upload.groupy.vip/avatar/14584F09-75CB-4531-A841-7ACF9CEF5BCC.jpg","giftId":10,"giftNums":13,"giftName":"流星雨","giftImg":"http://image.groupy.vip/gifts/gift_meteor.png","gprice":651157,"levelPlatform":103}]},{"id":10213,"idolId":20509,"activityId":1027,"active":1,"title":"参加了喔","introduce":" ","firstFrame":"http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/a9e82239e5484b5094d7756958421720/1000.jpg","thumbnail":"http://upload.groupy.vip/video_thumbnail/C82F1FFB-FCF6-4585-AEA5-C05B5816F025.jpg","thumbnailWidth":272,"thumbnailHeight":480,"videoWidth":272,"videoHeight":480,"publicType":0,"duration":10,"publishTime":1521106389000,"activity":{"id":1027,"title":"Groupy官方采访权争夺战","description":"Groupy官方采访权争夺战盛大开启!应援你的小偶像登上Like数排名TOP1,让更多人Get她的萌点吧~~~\r\n","rankingType":1,"position":1,"goal":"获得Like数TOP1","img":"http://image.groupy.vip/acticity_banner/activity-interview.png","tag":"Groupy独家采访","actionInfo":"http://activity.groupy.cn/interview/index.html?activityId\u003d1027","shareLink":"http://share.groupy.cn/html/activity_interview/index.html?activityId\u003d1027","shareTitle":"【#Groupy独家采访#】","shareDesc":"我家小偶像正在参加GroupyAPP的官方采访权争夺战,发了很多有趣视频,请大家多多支持!#Groupy#","startTime":1506787201000,"endTime":1522511999000,"type":2,"state":"inProgress","rankingList":[],"isActivityEnded":false},"activityTag":"Groupy独家采访","featureMask":0,"videoItemList":[{"id":4094,"videoId":10213,"resolution":"ld","url":"http://videodebug.groupy.vip/Act-ss-mp4-ld/a9e82239e5484b5094d7756958421720/BE1346E9-CA87-40E4-BBD3-6BBEC47783B2.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":996751},{"id":4095,"videoId":10213,"resolution":"hd","url":"http://videodebug.groupy.vip/Act-ss-mp4-hd/a9e82239e5484b5094d7756958421720/BE1346E9-CA87-40E4-BBD3-6BBEC47783B2.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":996751},{"id":4096,"videoId":10213,"resolution":"sd","url":"http://videodebug.groupy.vip/Act-ss-mp4-sd/a9e82239e5484b5094d7756958421720/BE1346E9-CA87-40E4-BBD3-6BBEC47783B2.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":996751}],"postList":[],"readCount":0,"popularity":22,"gcoin":6,"postCount":0,"giftCount":0,"idol":{"id":20509,"userType":"idol","gender":"unknown","nickname":"专做直播的小姐姐","avatar":"http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg","sign":"","introduce":"hi。\nhey……😈","imgs":"","levelPlatform":0,"dateOfBirth":927126000000,"placeOfBirth":"Guangdong Shenzhen🤔","bloodType":"A","organizationId":1,"fansNums":0,"followedIdol":false},"videoGifts":[{"fansId":20438,"nickname":"专做直播的小姐姐","avatar":"http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg","giftId":1,"giftNums":1,"giftName":"星星","giftImg":"http://image.groupy.vip/gifts/gift_star.png","gprice":1,"levelPlatform":103},{"fansId":20438,"nickname":"专做直播的小姐姐","avatar":"http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg","giftId":2,"giftNums":1,"giftName":"喜欢爱心","giftImg":"http://image.groupy.vip/gifts/gift_like.png","gprice":5,"levelPlatform":103}]},{"id":10214,"idolId":158,"activityId":1027,"active":1,"title":"😂","introduce":" ","firstFrame":"http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/176a825d7e9c4e74b9b8fefc76811542/1000.jpg","thumbnail":"http://upload.groupy.vip/video_thumbnail/5D6D460C-1F2A-40DA-9CDC-10583DFB5378.jpg","thumbnailWidth":272,"thumbnailHeight":480,"videoWidth":272,"videoHeight":480,"publicType":0,"duration":10,"publishTime":1521106626000,"activity":{"id":1027,"title":"Groupy官方采访权争夺战","description":"Groupy官方采访权争夺战盛大开启!应援你的小偶像登上Like数排名TOP1,让更多人Get她的萌点吧~~~\r\n","rankingType":1,"position":1,"goal":"获得Like数TOP1","img":"http://image.groupy.vip/acticity_banner/activity-interview.png","tag":"Groupy独家采访","actionInfo":"http://activity.groupy.cn/interview/index.html?activityId\u003d1027","shareLink":"http://share.groupy.cn/html/activity_interview/index.html?activityId\u003d1027","shareTitle":"【#Groupy独家采访#】","shareDesc":"我家小偶像正在参加GroupyAPP的官方采访权争夺战,发了很多有趣视频,请大家多多支持!#Groupy#","startTime":1506787201000,"endTime":1522511999000,"type":2,"state":"inProgress","rankingList":[],"isActivityEnded":false},"activityTag":"Groupy独家采访","featureMask":0,"videoItemList":[{"id":4097,"videoId":10214,"resolution":"sd","url":"http://videodebug.groupy.vip/Act-ss-mp4-sd/176a825d7e9c4e74b9b8fefc76811542/2BBFD219-1B08-4A62-BD57-9407F1828D85.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":703556},{"id":4098,"videoId":10214,"resolution":"hd","url":"http://videodebug.groupy.vip/Act-ss-mp4-hd/176a825d7e9c4e74b9b8fefc76811542/2BBFD219-1B08-4A62-BD57-9407F1828D85.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":703556},{"id":4099,"videoId":10214,"resolution":"ld","url":"http://videodebug.groupy.vip/Act-ss-mp4-ld/176a825d7e9c4e74b9b8fefc76811542/2BBFD219-1B08-4A62-BD57-9407F1828D85.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":703556}],"postList":[],"readCount":0,"popularity":8,"gcoin":0,"postCount":0,"giftCount":0,"idol":{"id":158,"userType":"idol","gender":"unknown","nickname":"妈妈说名字长一点可以看到一般人看不到的bug😁g","avatar":"http://upload.groupy.vip/avatar/F7357D2B-C304-43EB-9796-9824B3E14E2A.jpg","sign":"","introduce":"","imgs":"","levelPlatform":0,"dateOfBirth":776962800000,"bloodType":"Unknown","organizationId":3,"fansNums":0,"followedIdol":false},"videoGifts":[]},{"id":10206,"idolId":20509,"activityId":0,"active":1,"title":"hi","introduce":" ","firstFrame":"http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/30c7e3f636464284afc8c51272f26ee1/1000.jpg","thumbnail":"http://upload.groupy.vip/video_thumbnail/12DE0D9E-EBFD-4550-A886-068A1CDCD9DF.jpg","thumbnailWidth":360,"thumbnailHeight":480,"videoWidth":360,"videoHeight":480,"publicType":0,"duration":6,"publishTime":1520215497000,"featureMask":0,"videoItemList":[],"postList":[],"readCount":0,"popularity":101,"gcoin":5,"postCount":0,"giftCount":0,"idol":{"id":20509,"userType":"idol","gender":"unknown","nickname":"专做直播的小姐姐","avatar":"http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg","sign":"","introduce":"hi。\nhey……😈","imgs":"","levelPlatform":0,"dateOfBirth":927126000000,"placeOfBirth":"Guangdong Shenzhen🤔","bloodType":"A","organizationId":1,"fansNums":0,"followedIdol":false},"videoGifts":[{"fansId":20440,"nickname":"豆奶豆奶","avatar":"http://upload.groupy.vip/avatar/01FAB3E3-FE0D-4B14-BDC8-4C51C700A659.jpg","giftId":2,"giftNums":1,"giftName":"喜欢爱心","giftImg":"http://image.groupy.vip/gifts/gift_like.png","gprice":5,"levelPlatform":103}]},{"id":10222,"idolId":21421,"activityId":1025,"active":1,"title":"冷漠","introduce":" ","firstFrame":"http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/65717d41ac6d4c548de6ac671878a601/1000.jpg","thumbnail":"http://upload.groupy.vip/video_thumbnail/29053E43-FA51-46F9-ACA0-291D27C61E62.jpg","thumbnailWidth":272,"thumbnailHeight":480,"videoWidth":272,"videoHeight":480,"publicType":0,"duration":10,"publishTime":1521111025000,"activity":{"id":1025,"title":"FFACG x Groupy\r\n広告モデル選定企画","description":"上位1名のアイドルは、中国広州で開催予定の来場者数20万人超えの18th FFACGに、Groupyの広告モデルとして特大看板に登場できます!","rankingType":1,"position":1,"goal":"上位1名","img":"http://image.groupy.vip/acticity_banner/activity-ffacg201805.jpg","tag":"Groupy広告モデル1","actionInfo":"http://activity.groupy.cn/ffacg201805/index.html?activityId\u003d1025","shareLink":"http://share.groupy.cn/html/activity_ffacg201805/index.html?activityId\u003d1025","shareTitle":"【#Groupy広告モデル1 】","shareDesc":"上位1名は来場者数20万人超えの中国広州FFACG特大看板に掲載!応援しよう!","startTime":1506787201000,"endTime":1525190399000,"type":2,"state":"inProgress","rankingList":[],"isActivityEnded":false},"activityTag":"Groupy広告モデル1","featureMask":0,"videoItemList":[{"id":4121,"videoId":10222,"resolution":"hd","url":"http://videodebug.groupy.vip/Act-ss-mp4-hd/65717d41ac6d4c548de6ac671878a601/865DFD74-7A77-443F-9775-6E64FCFD2AD1.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752},{"id":4122,"videoId":10222,"resolution":"sd","url":"http://videodebug.groupy.vip/Act-ss-mp4-sd/65717d41ac6d4c548de6ac671878a601/865DFD74-7A77-443F-9775-6E64FCFD2AD1.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752},{"id":4123,"videoId":10222,"resolution":"ld","url":"http://videodebug.groupy.vip/Act-ss-mp4-ld/65717d41ac6d4c548de6ac671878a601/865DFD74-7A77-443F-9775-6E64FCFD2AD1.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752}],"postList":[],"readCount":0,"popularity":0,"gcoin":0,"postCount":0,"giftCount":0,"idol":{"id":21421,"userType":"idol","gender":"unknown","nickname":"爱笑的人h健容易坏","avatar":"http://upload.groupy.vip/avatar/1ba403c9-b460-434c-91e9-2fa1e32545bc.jpg","sign":"","introduce":"","imgs":"","levelPlatform":0,"dateOfBirth":-32400000,"bloodType":"Unknown","organizationId":20,"fansNums":0,"followedIdol":false},"videoGifts":[]},{"id":10220,"idolId":20509,"activityId":0,"active":1,"title":"页","introduce":" ","firstFrame":"http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/7fc826466afd447899d1e6b4ae9855ce/1000.jpg","thumbnail":"http://upload.groupy.vip/video_thumbnail/DB17ED85-04DF-448F-A9E5-BEE785486AD5.jpg","thumbnailWidth":272,"thumbnailHeight":480,"videoWidth":272,"videoHeight":480,"publicType":0,"duration":10,"publishTime":1521107491000,"featureMask":0,"videoItemList":[{"id":4115,"videoId":10220,"resolution":"sd","url":"http://videodebug.groupy.vip/Act-ss-mp4-sd/7fc826466afd447899d1e6b4ae9855ce/6AD565F5-ACFD-428E-A22E-00A24965D8E8.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752},{"id":4116,"videoId":10220,"resolution":"hd","url":"http://videodebug.groupy.vip/Act-ss-mp4-hd/7fc826466afd447899d1e6b4ae9855ce/6AD565F5-ACFD-428E-A22E-00A24965D8E8.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752},{"id":4117,"videoId":10220,"resolution":"ld","url":"http://videodebug.groupy.vip/Act-ss-mp4-ld/7fc826466afd447899d1e6b4ae9855ce/6AD565F5-ACFD-428E-A22E-00A24965D8E8.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752}],"postList":[],"readCount":0,"popularity":0,"gcoin":0,"postCount":0,"giftCount":0,"idol":{"id":20509,"userType":"idol","gender":"unknown","nickname":"专做直播的小姐姐","avatar":"http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg","sign":"","introduce":"hi。\nhey……😈","imgs":"","levelPlatform":0,"dateOfBirth":927126000000,"placeOfBirth":"Guangdong Shenzhen🤔","bloodType":"A","organizationId":1,"fansNums":0,"followedIdol":false},"videoGifts":[]},{"id":10219,"idolId":20509,"activityId":1027,"active":1,"title":"哈哈","introduce":" ","firstFrame":"http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/a3062ce33b5d49ab8d2e37669294e820/1000.jpg","thumbnail":"http://upload.groupy.vip/video_thumbnail/F370AEEA-0E6B-4A9F-ADD6-87E2651EA820.jpg","thumbnailWidth":272,"thumbnailHeight":480,"videoWidth":272,"videoHeight":480,"publicType":0,"duration":10,"publishTime":1521107416000,"activity":{"id":1027,"title":"Groupy官方采访权争夺战","description":"Groupy官方采访权争夺战盛大开启!应援你的小偶像登上Like数排名TOP1,让更多人Get她的萌点吧~~~\r\n","rankingType":1,"position":1,"goal":"获得Like数TOP1","img":"http://image.groupy.vip/acticity_banner/activity-interview.png","tag":"Groupy独家采访","actionInfo":"http://activity.groupy.cn/interview/index.html?activityId\u003d1027","shareLink":"http://share.groupy.cn/html/activity_interview/index.html?activityId\u003d1027","shareTitle":"【#Groupy独家采访#】","shareDesc":"我家小偶像正在参加GroupyAPP的官方采访权争夺战,发了很多有趣视频,请大家多多支持!#Groupy#","startTime":1506787201000,"endTime":1522511999000,"type":2,"state":"inProgress","rankingList":[],"isActivityEnded":false},"activityTag":"Groupy独家采访","featureMask":0,"videoItemList":[{"id":4112,"videoId":10219,"resolution":"hd","url":"http://videodebug.groupy.vip/Act-ss-mp4-hd/a3062ce33b5d49ab8d2e37669294e820/8B2B2087-FB9F-4D05-86FC-99A561E21A55.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752},{"id":4113,"videoId":10219,"resolution":"ld","url":"http://videodebug.groupy.vip/Act-ss-mp4-ld/a3062ce33b5d49ab8d2e37669294e820/8B2B2087-FB9F-4D05-86FC-99A561E21A55.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752},{"id":4114,"videoId":10219,"resolution":"sd","url":"http://videodebug.groupy.vip/Act-ss-mp4-sd/a3062ce33b5d49ab8d2e37669294e820/8B2B2087-FB9F-4D05-86FC-99A561E21A55.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752}],"postList":[],"readCount":0,"popularity":0,"gcoin":0,"postCount":0,"giftCount":0,"idol":{"id":20509,"userType":"idol","gender":"unknown","nickname":"专做直播的小姐姐","avatar":"http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg","sign":"","introduce":"hi。\nhey……😈","imgs":"","levelPlatform":0,"dateOfBirth":927126000000,"placeOfBirth":"Guangdong Shenzhen🤔","bloodType":"A","organizationId":1,"fansNums":0,"followedIdol":false},"videoGifts":[]},{"id":10218,"idolId":20509,"activityId":0,"active":1,"title":"来了","introduce":" ","firstFrame":"http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/c98dba44b149484f88aa72877d08a07f/1000.jpg","thumbnail":"http://upload.groupy.vip/video_thumbnail/4CD900DD-1A4A-4473-B68E-2F00FEFEF5C9.jpg","thumbnailWidth":272,"thumbnailHeight":480,"videoWidth":272,"videoHeight":480,"publicType":0,"duration":10,"publishTime":1521107356000,"featureMask":0,"videoItemList":[{"id":4109,"videoId":10218,"resolution":"ld","url":"http://videodebug.groupy.vip/Act-ss-mp4-ld/c98dba44b149484f88aa72877d08a07f/4F01D0A5-CC29-4463-8709-6D68AC1A1CD5.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752},{"id":4110,"videoId":10218,"resolution":"sd","url":"http://videodebug.groupy.vip/Act-ss-mp4-sd/c98dba44b149484f88aa72877d08a07f/4F01D0A5-CC29-4463-8709-6D68AC1A1CD5.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752},{"id":4111,"videoId":10218,"resolution":"hd","url":"http://videodebug.groupy.vip/Act-ss-mp4-hd/c98dba44b149484f88aa72877d08a07f/4F01D0A5-CC29-4463-8709-6D68AC1A1CD5.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752}],"postList":[],"readCount":0,"popularity":0,"gcoin":0,"postCount":0,"giftCount":0,"idol":{"id":20509,"userType":"idol","gender":"unknown","nickname":"专做直播的小姐姐","avatar":"http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg","sign":"","introduce":"hi。\nhey……😈","imgs":"","levelPlatform":0,"dateOfBirth":927126000000,"placeOfBirth":"Guangdong Shenzhen🤔","bloodType":"A","organizationId":1,"fansNums":0,"followedIdol":false},"videoGifts":[]},{"id":10217,"idolId":158,"activityId":0,"active":1,"title":"2","introduce":" ","firstFrame":"http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/f455f5d01da148f095af77382e292364/1000.jpg","thumbnail":"http://upload.groupy.vip/video_thumbnail/A69EC31D-5FF2-4993-8A81-24417EF34BBE.jpg","thumbnailWidth":272,"thumbnailHeight":480,"videoWidth":272,"videoHeight":480,"publicType":0,"duration":10,"publishTime":1521107247000,"featureMask":0,"videoItemList":[{"id":4106,"videoId":10217,"resolution":"ld","url":"http://videodebug.groupy.vip/Act-ss-mp4-ld/f455f5d01da148f095af77382e292364/BEA0FDCC-60EA-42C5-BB26-E59EB533C6EB.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752},{"id":4107,"videoId":10217,"resolution":"hd","url":"http://videodebug.groupy.vip/Act-ss-mp4-hd/f455f5d01da148f095af77382e292364/BEA0FDCC-60EA-42C5-BB26-E59EB533C6EB.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752},{"id":4108,"videoId":10217,"resolution":"sd","url":"http://videodebug.groupy.vip/Act-ss-mp4-sd/f455f5d01da148f095af77382e292364/BEA0FDCC-60EA-42C5-BB26-E59EB533C6EB.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752}],"postList":[],"readCount":0,"popularity":0,"gcoin":0,"postCount":0,"giftCount":0,"idol":{"id":158,"userType":"idol","gender":"unknown","nickname":"妈妈说名字长一点可以看到一般人看不到的bug😁g","avatar":"http://upload.groupy.vip/avatar/F7357D2B-C304-43EB-9796-9824B3E14E2A.jpg","sign":"","introduce":"","imgs":"","levelPlatform":0,"dateOfBirth":776962800000,"bloodType":"Unknown","organizationId":3,"fansNums":0,"followedIdol":false},"videoGifts":[]},{"id":10216,"idolId":158,"activityId":0,"active":1,"title":"参加","introduce":" ","firstFrame":"http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/5781f5ff83de40b981f90fbb299ba72b/1000.jpg","thumbnail":"http://upload.groupy.vip/video_thumbnail/67F05E3B-EC1A-41E1-8DC2-11D924C16038.jpg","thumbnailWidth":272,"thumbnailHeight":480,"videoWidth":272,"videoHeight":480,"publicType":0,"duration":10,"publishTime":1521107209000,"featureMask":0,"videoItemList":[{"id":4103,"videoId":10216,"resolution":"ld","url":"http://videodebug.groupy.vip/Act-ss-mp4-ld/5781f5ff83de40b981f90fbb299ba72b/2581A732-12C4-48C7-BB71-723F98C0D7C3.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752},{"id":4104,"videoId":10216,"resolution":"hd","url":"http://videodebug.groupy.vip/Act-ss-mp4-hd/5781f5ff83de40b981f90fbb299ba72b/2581A732-12C4-48C7-BB71-723F98C0D7C3.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752},{"id":4105,"videoId":10216,"resolution":"sd","url":"http://videodebug.groupy.vip/Act-ss-mp4-sd/5781f5ff83de40b981f90fbb299ba72b/2581A732-12C4-48C7-BB71-723F98C0D7C3.mp4","width":272,"height":480,"fps":25,"duration":10,"filesize":808752}],"postList":[],"readCount":0,"popularity":0,"gcoin":0,"postCount":0,"giftCount":0,"idol":{"id":158,"userType":"idol","gender":"unknown","nickname":"妈妈说名字长一点可以看到一般人看不到的bug😁g","avatar":"http://upload.groupy.vip/avatar/F7357D2B-C304-43EB-9796-9824B3E14E2A.jpg","sign":"","introduce":"","imgs":"","levelPlatform":0,"dateOfBirth":776962800000,"bloodType":"Unknown","organizationId":3,"fansNums":0,"followedIdol":false},"videoGifts":[]}]}

jq 基础用法

这里 查看 jq 的完整手册

使用 jq 格式化 json

1
$ echo '{"key": "value"}' | jq

以上命令 echo 命令打印字符串 {"key": "value"} 到控制台, 管道符 (pipeline) | 将前面的命令的输出作为后面 jq 的输入, jq 会格式化该字符串;

1
$ cat /tmp/test.json | jq

以上命令将文件 /tmp/test.json 的内容打印到控制台, 管道符 (pipeline) | 将前面的命令的输出作为后面 jq 的输入, 因此该命令是将文件 /tmp/test.json 内的字符串作为 jq 命令的输入, 来运行 jq 命令;

使用 jq 格式化 json 文件也可以使用以下用法:

1
$ jq . /tmp/test.json

其中 .jq 的一种过滤器, 表示把格式化后的 json 原样打印出来, 更多的过滤器参见后文;

格式化后的 test-formatted.jsonview raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
{
"status": 200,
"errorMsg": "Operation OK!",
"data": [
{
"id": 10202,
"idolId": 158,
"activityId": 1026,
"active": 1,
"title": "可以",
"introduce": " ",
"firstFrame": "http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/e07821a403a442bfa27e1bcd037c50a5/1000.jpg",
"thumbnail": "http://upload.groupy.vip/video_thumbnail/2068135D-3AC8-4BB7-B982-48176A42DED2.jpg",
"thumbnailWidth": 360,
"thumbnailHeight": 480,
"videoWidth": 360,
"videoHeight": 480,
"publicType": 0,
"duration": 3,
"publishTime": 1519804082000,
"activity": {
"id": 1026,
"title": "麦萌 x Groupy",
"description": "1位のアイドルはユーザー数が1000万人超えの中国最大級アフレコアプリ「麦萌対手戏」に声で出演!推しメンを応援してね~♪",
"rankingType": 1,
"position": 1,
"goal": "ランキング上位1名のアイドル",
"img": "http://image.groupy.vip/acticity_banner/activity-maimeng.jpg",
"tag": "Groupyx麦萌",
"actionInfo": "http://activity.groupy.cn/maimeng/index.html?activityId=1026",
"shareLink": "http://share.groupy.cn/html/activity_maimeng/index.html?activityId=1026",
"shareTitle": "【#Groupyx麦萌コラボ 】",
"shareDesc": "上位1名は中国最大級アフレコアプリ「麦萌対手戏」に声で出演!応援しよう!",
"startTime": 1506787201000,
"endTime": 1525190399000,
"type": 2,
"state": "inProgress",
"rankingList": [],
"isActivityEnded": false
},
"activityTag": "Groupyx麦萌",
"featureMask": 0,
"videoItemList": [],
"postList": [],
"readCount": 3,
"popularity": 1393369,
"gcoin": 696674,
"postCount": 0,
"giftCount": 0,
"idol": {
"id": 158,
"userType": "idol",
"gender": "unknown",
"nickname": "妈妈说名字长一点可以看到一般人看不到的bug😁g",
"avatar": "http://upload.groupy.vip/avatar/F7357D2B-C304-43EB-9796-9824B3E14E2A.jpg",
"sign": "",
"introduce": "",
"imgs": "",
"levelPlatform": 0,
"dateOfBirth": 776962800000,
"bloodType": "Unknown",
"organizationId": 3,
"fansNums": 0,
"followedIdol": false
},
"videoGifts": [
{
"fansId": 20295,
"nickname": "抖腿ing,名字要很长才不会抖输别人",
"avatar": "http://upload.groupy.vip/avatar/14584F09-75CB-4531-A841-7ACF9CEF5BCC.jpg",
"giftId": 5,
"giftNums": 1,
"giftName": "熊",
"giftImg": "http://image.groupy.vip/gifts/gift_bear.png",
"gprice": 122,
"levelPlatform": 103
},
{
"fansId": 20295,
"nickname": "抖腿ing,名字要很长才不会抖输别人",
"avatar": "http://upload.groupy.vip/avatar/14584F09-75CB-4531-A841-7ACF9CEF5BCC.jpg",
"giftId": 14,
"giftNums": 2,
"giftName": "超级拉面",
"giftImg": "http://image.groupy.vip/gifts/gift_noodles.png",
"gprice": 538,
"levelPlatform": 103
},
{
"fansId": 20295,
"nickname": "抖腿ing,名字要很长才不会抖输别人",
"avatar": "http://upload.groupy.vip/avatar/14584F09-75CB-4531-A841-7ACF9CEF5BCC.jpg",
"giftId": 8,
"giftNums": 1,
"giftName": "迪士尼城堡",
"giftImg": "http://image.groupy.vip/gifts/gift_castle.png",
"gprice": 2929,
"levelPlatform": 103
},
{
"fansId": 20295,
"nickname": "抖腿ing,名字要很长才不会抖输别人",
"avatar": "http://upload.groupy.vip/avatar/14584F09-75CB-4531-A841-7ACF9CEF5BCC.jpg",
"giftId": 12,
"giftNums": 6,
"giftName": "红叶林",
"giftImg": "http://image.groupy.vip/gifts/gift_maple.png",
"gprice": 41928,
"levelPlatform": 103
},
{
"fansId": 20295,
"nickname": "抖腿ing,名字要很长才不会抖输别人",
"avatar": "http://upload.groupy.vip/avatar/14584F09-75CB-4531-A841-7ACF9CEF5BCC.jpg",
"giftId": 10,
"giftNums": 13,
"giftName": "流星雨",
"giftImg": "http://image.groupy.vip/gifts/gift_meteor.png",
"gprice": 651157,
"levelPlatform": 103
}
]
},
{
"id": 10213,
"idolId": 20509,
"activityId": 1027,
"active": 1,
"title": "参加了喔",
"introduce": " ",
"firstFrame": "http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/a9e82239e5484b5094d7756958421720/1000.jpg",
"thumbnail": "http://upload.groupy.vip/video_thumbnail/C82F1FFB-FCF6-4585-AEA5-C05B5816F025.jpg",
"thumbnailWidth": 272,
"thumbnailHeight": 480,
"videoWidth": 272,
"videoHeight": 480,
"publicType": 0,
"duration": 10,
"publishTime": 1521106389000,
"activity": {
"id": 1027,
"title": "Groupy官方采访权争夺战",
"description": "Groupy官方采访权争夺战盛大开启!应援你的小偶像登上Like数排名TOP1,让更多人Get她的萌点吧~~~\r\n",
"rankingType": 1,
"position": 1,
"goal": "获得Like数TOP1",
"img": "http://image.groupy.vip/acticity_banner/activity-interview.png",
"tag": "Groupy独家采访",
"actionInfo": "http://activity.groupy.cn/interview/index.html?activityId=1027",
"shareLink": "http://share.groupy.cn/html/activity_interview/index.html?activityId=1027",
"shareTitle": "【#Groupy独家采访#】",
"shareDesc": "我家小偶像正在参加GroupyAPP的官方采访权争夺战,发了很多有趣视频,请大家多多支持!#Groupy#",
"startTime": 1506787201000,
"endTime": 1522511999000,
"type": 2,
"state": "inProgress",
"rankingList": [],
"isActivityEnded": false
},
"activityTag": "Groupy独家采访",
"featureMask": 0,
"videoItemList": [
{
"id": 4094,
"videoId": 10213,
"resolution": "ld",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-ld/a9e82239e5484b5094d7756958421720/BE1346E9-CA87-40E4-BBD3-6BBEC47783B2.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 996751
},
{
"id": 4095,
"videoId": 10213,
"resolution": "hd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-hd/a9e82239e5484b5094d7756958421720/BE1346E9-CA87-40E4-BBD3-6BBEC47783B2.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 996751
},
{
"id": 4096,
"videoId": 10213,
"resolution": "sd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-sd/a9e82239e5484b5094d7756958421720/BE1346E9-CA87-40E4-BBD3-6BBEC47783B2.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 996751
}
],
"postList": [],
"readCount": 0,
"popularity": 22,
"gcoin": 6,
"postCount": 0,
"giftCount": 0,
"idol": {
"id": 20509,
"userType": "idol",
"gender": "unknown",
"nickname": "专做直播的小姐姐",
"avatar": "http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg",
"sign": "",
"introduce": "hi。\nhey……😈",
"imgs": "",
"levelPlatform": 0,
"dateOfBirth": 927126000000,
"placeOfBirth": "Guangdong Shenzhen🤔",
"bloodType": "A",
"organizationId": 1,
"fansNums": 0,
"followedIdol": false
},
"videoGifts": [
{
"fansId": 20438,
"nickname": "专做直播的小姐姐",
"avatar": "http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg",
"giftId": 1,
"giftNums": 1,
"giftName": "星星",
"giftImg": "http://image.groupy.vip/gifts/gift_star.png",
"gprice": 1,
"levelPlatform": 103
},
{
"fansId": 20438,
"nickname": "专做直播的小姐姐",
"avatar": "http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg",
"giftId": 2,
"giftNums": 1,
"giftName": "喜欢爱心",
"giftImg": "http://image.groupy.vip/gifts/gift_like.png",
"gprice": 5,
"levelPlatform": 103
}
]
},
{
"id": 10214,
"idolId": 158,
"activityId": 1027,
"active": 1,
"title": "😂",
"introduce": " ",
"firstFrame": "http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/176a825d7e9c4e74b9b8fefc76811542/1000.jpg",
"thumbnail": "http://upload.groupy.vip/video_thumbnail/5D6D460C-1F2A-40DA-9CDC-10583DFB5378.jpg",
"thumbnailWidth": 272,
"thumbnailHeight": 480,
"videoWidth": 272,
"videoHeight": 480,
"publicType": 0,
"duration": 10,
"publishTime": 1521106626000,
"activity": {
"id": 1027,
"title": "Groupy官方采访权争夺战",
"description": "Groupy官方采访权争夺战盛大开启!应援你的小偶像登上Like数排名TOP1,让更多人Get她的萌点吧~~~\r\n",
"rankingType": 1,
"position": 1,
"goal": "获得Like数TOP1",
"img": "http://image.groupy.vip/acticity_banner/activity-interview.png",
"tag": "Groupy独家采访",
"actionInfo": "http://activity.groupy.cn/interview/index.html?activityId=1027",
"shareLink": "http://share.groupy.cn/html/activity_interview/index.html?activityId=1027",
"shareTitle": "【#Groupy独家采访#】",
"shareDesc": "我家小偶像正在参加GroupyAPP的官方采访权争夺战,发了很多有趣视频,请大家多多支持!#Groupy#",
"startTime": 1506787201000,
"endTime": 1522511999000,
"type": 2,
"state": "inProgress",
"rankingList": [],
"isActivityEnded": false
},
"activityTag": "Groupy独家采访",
"featureMask": 0,
"videoItemList": [
{
"id": 4097,
"videoId": 10214,
"resolution": "sd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-sd/176a825d7e9c4e74b9b8fefc76811542/2BBFD219-1B08-4A62-BD57-9407F1828D85.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 703556
},
{
"id": 4098,
"videoId": 10214,
"resolution": "hd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-hd/176a825d7e9c4e74b9b8fefc76811542/2BBFD219-1B08-4A62-BD57-9407F1828D85.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 703556
},
{
"id": 4099,
"videoId": 10214,
"resolution": "ld",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-ld/176a825d7e9c4e74b9b8fefc76811542/2BBFD219-1B08-4A62-BD57-9407F1828D85.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 703556
}
],
"postList": [],
"readCount": 0,
"popularity": 8,
"gcoin": 0,
"postCount": 0,
"giftCount": 0,
"idol": {
"id": 158,
"userType": "idol",
"gender": "unknown",
"nickname": "妈妈说名字长一点可以看到一般人看不到的bug😁g",
"avatar": "http://upload.groupy.vip/avatar/F7357D2B-C304-43EB-9796-9824B3E14E2A.jpg",
"sign": "",
"introduce": "",
"imgs": "",
"levelPlatform": 0,
"dateOfBirth": 776962800000,
"bloodType": "Unknown",
"organizationId": 3,
"fansNums": 0,
"followedIdol": false
},
"videoGifts": []
},
{
"id": 10206,
"idolId": 20509,
"activityId": 0,
"active": 1,
"title": "hi",
"introduce": " ",
"firstFrame": "http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/30c7e3f636464284afc8c51272f26ee1/1000.jpg",
"thumbnail": "http://upload.groupy.vip/video_thumbnail/12DE0D9E-EBFD-4550-A886-068A1CDCD9DF.jpg",
"thumbnailWidth": 360,
"thumbnailHeight": 480,
"videoWidth": 360,
"videoHeight": 480,
"publicType": 0,
"duration": 6,
"publishTime": 1520215497000,
"featureMask": 0,
"videoItemList": [],
"postList": [],
"readCount": 0,
"popularity": 101,
"gcoin": 5,
"postCount": 0,
"giftCount": 0,
"idol": {
"id": 20509,
"userType": "idol",
"gender": "unknown",
"nickname": "专做直播的小姐姐",
"avatar": "http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg",
"sign": "",
"introduce": "hi。\nhey……😈",
"imgs": "",
"levelPlatform": 0,
"dateOfBirth": 927126000000,
"placeOfBirth": "Guangdong Shenzhen🤔",
"bloodType": "A",
"organizationId": 1,
"fansNums": 0,
"followedIdol": false
},
"videoGifts": [
{
"fansId": 20440,
"nickname": "豆奶豆奶",
"avatar": "http://upload.groupy.vip/avatar/01FAB3E3-FE0D-4B14-BDC8-4C51C700A659.jpg",
"giftId": 2,
"giftNums": 1,
"giftName": "喜欢爱心",
"giftImg": "http://image.groupy.vip/gifts/gift_like.png",
"gprice": 5,
"levelPlatform": 103
}
]
},
{
"id": 10222,
"idolId": 21421,
"activityId": 1025,
"active": 1,
"title": "冷漠",
"introduce": " ",
"firstFrame": "http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/65717d41ac6d4c548de6ac671878a601/1000.jpg",
"thumbnail": "http://upload.groupy.vip/video_thumbnail/29053E43-FA51-46F9-ACA0-291D27C61E62.jpg",
"thumbnailWidth": 272,
"thumbnailHeight": 480,
"videoWidth": 272,
"videoHeight": 480,
"publicType": 0,
"duration": 10,
"publishTime": 1521111025000,
"activity": {
"id": 1025,
"title": "FFACG x Groupy\r\n広告モデル選定企画",
"description": "上位1名のアイドルは、中国広州で開催予定の来場者数20万人超えの18th FFACGに、Groupyの広告モデルとして特大看板に登場できます!",
"rankingType": 1,
"position": 1,
"goal": "上位1名",
"img": "http://image.groupy.vip/acticity_banner/activity-ffacg201805.jpg",
"tag": "Groupy広告モデル1",
"actionInfo": "http://activity.groupy.cn/ffacg201805/index.html?activityId=1025",
"shareLink": "http://share.groupy.cn/html/activity_ffacg201805/index.html?activityId=1025",
"shareTitle": "【#Groupy広告モデル1 】",
"shareDesc": "上位1名は来場者数20万人超えの中国広州FFACG特大看板に掲載!応援しよう!",
"startTime": 1506787201000,
"endTime": 1525190399000,
"type": 2,
"state": "inProgress",
"rankingList": [],
"isActivityEnded": false
},
"activityTag": "Groupy広告モデル1",
"featureMask": 0,
"videoItemList": [
{
"id": 4121,
"videoId": 10222,
"resolution": "hd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-hd/65717d41ac6d4c548de6ac671878a601/865DFD74-7A77-443F-9775-6E64FCFD2AD1.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
},
{
"id": 4122,
"videoId": 10222,
"resolution": "sd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-sd/65717d41ac6d4c548de6ac671878a601/865DFD74-7A77-443F-9775-6E64FCFD2AD1.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
},
{
"id": 4123,
"videoId": 10222,
"resolution": "ld",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-ld/65717d41ac6d4c548de6ac671878a601/865DFD74-7A77-443F-9775-6E64FCFD2AD1.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
}
],
"postList": [],
"readCount": 0,
"popularity": 0,
"gcoin": 0,
"postCount": 0,
"giftCount": 0,
"idol": {
"id": 21421,
"userType": "idol",
"gender": "unknown",
"nickname": "爱笑的人h健容易坏",
"avatar": "http://upload.groupy.vip/avatar/1ba403c9-b460-434c-91e9-2fa1e32545bc.jpg",
"sign": "",
"introduce": "",
"imgs": "",
"levelPlatform": 0,
"dateOfBirth": -32400000,
"bloodType": "Unknown",
"organizationId": 20,
"fansNums": 0,
"followedIdol": false
},
"videoGifts": []
},
{
"id": 10220,
"idolId": 20509,
"activityId": 0,
"active": 1,
"title": "页",
"introduce": " ",
"firstFrame": "http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/7fc826466afd447899d1e6b4ae9855ce/1000.jpg",
"thumbnail": "http://upload.groupy.vip/video_thumbnail/DB17ED85-04DF-448F-A9E5-BEE785486AD5.jpg",
"thumbnailWidth": 272,
"thumbnailHeight": 480,
"videoWidth": 272,
"videoHeight": 480,
"publicType": 0,
"duration": 10,
"publishTime": 1521107491000,
"featureMask": 0,
"videoItemList": [
{
"id": 4115,
"videoId": 10220,
"resolution": "sd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-sd/7fc826466afd447899d1e6b4ae9855ce/6AD565F5-ACFD-428E-A22E-00A24965D8E8.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
},
{
"id": 4116,
"videoId": 10220,
"resolution": "hd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-hd/7fc826466afd447899d1e6b4ae9855ce/6AD565F5-ACFD-428E-A22E-00A24965D8E8.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
},
{
"id": 4117,
"videoId": 10220,
"resolution": "ld",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-ld/7fc826466afd447899d1e6b4ae9855ce/6AD565F5-ACFD-428E-A22E-00A24965D8E8.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
}
],
"postList": [],
"readCount": 0,
"popularity": 0,
"gcoin": 0,
"postCount": 0,
"giftCount": 0,
"idol": {
"id": 20509,
"userType": "idol",
"gender": "unknown",
"nickname": "专做直播的小姐姐",
"avatar": "http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg",
"sign": "",
"introduce": "hi。\nhey……😈",
"imgs": "",
"levelPlatform": 0,
"dateOfBirth": 927126000000,
"placeOfBirth": "Guangdong Shenzhen🤔",
"bloodType": "A",
"organizationId": 1,
"fansNums": 0,
"followedIdol": false
},
"videoGifts": []
},
{
"id": 10219,
"idolId": 20509,
"activityId": 1027,
"active": 1,
"title": "哈哈",
"introduce": " ",
"firstFrame": "http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/a3062ce33b5d49ab8d2e37669294e820/1000.jpg",
"thumbnail": "http://upload.groupy.vip/video_thumbnail/F370AEEA-0E6B-4A9F-ADD6-87E2651EA820.jpg",
"thumbnailWidth": 272,
"thumbnailHeight": 480,
"videoWidth": 272,
"videoHeight": 480,
"publicType": 0,
"duration": 10,
"publishTime": 1521107416000,
"activity": {
"id": 1027,
"title": "Groupy官方采访权争夺战",
"description": "Groupy官方采访权争夺战盛大开启!应援你的小偶像登上Like数排名TOP1,让更多人Get她的萌点吧~~~\r\n",
"rankingType": 1,
"position": 1,
"goal": "获得Like数TOP1",
"img": "http://image.groupy.vip/acticity_banner/activity-interview.png",
"tag": "Groupy独家采访",
"actionInfo": "http://activity.groupy.cn/interview/index.html?activityId=1027",
"shareLink": "http://share.groupy.cn/html/activity_interview/index.html?activityId=1027",
"shareTitle": "【#Groupy独家采访#】",
"shareDesc": "我家小偶像正在参加GroupyAPP的官方采访权争夺战,发了很多有趣视频,请大家多多支持!#Groupy#",
"startTime": 1506787201000,
"endTime": 1522511999000,
"type": 2,
"state": "inProgress",
"rankingList": [],
"isActivityEnded": false
},
"activityTag": "Groupy独家采访",
"featureMask": 0,
"videoItemList": [
{
"id": 4112,
"videoId": 10219,
"resolution": "hd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-hd/a3062ce33b5d49ab8d2e37669294e820/8B2B2087-FB9F-4D05-86FC-99A561E21A55.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
},
{
"id": 4113,
"videoId": 10219,
"resolution": "ld",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-ld/a3062ce33b5d49ab8d2e37669294e820/8B2B2087-FB9F-4D05-86FC-99A561E21A55.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
},
{
"id": 4114,
"videoId": 10219,
"resolution": "sd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-sd/a3062ce33b5d49ab8d2e37669294e820/8B2B2087-FB9F-4D05-86FC-99A561E21A55.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
}
],
"postList": [],
"readCount": 0,
"popularity": 0,
"gcoin": 0,
"postCount": 0,
"giftCount": 0,
"idol": {
"id": 20509,
"userType": "idol",
"gender": "unknown",
"nickname": "专做直播的小姐姐",
"avatar": "http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg",
"sign": "",
"introduce": "hi。\nhey……😈",
"imgs": "",
"levelPlatform": 0,
"dateOfBirth": 927126000000,
"placeOfBirth": "Guangdong Shenzhen🤔",
"bloodType": "A",
"organizationId": 1,
"fansNums": 0,
"followedIdol": false
},
"videoGifts": []
},
{
"id": 10218,
"idolId": 20509,
"activityId": 0,
"active": 1,
"title": "来了",
"introduce": " ",
"firstFrame": "http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/c98dba44b149484f88aa72877d08a07f/1000.jpg",
"thumbnail": "http://upload.groupy.vip/video_thumbnail/4CD900DD-1A4A-4473-B68E-2F00FEFEF5C9.jpg",
"thumbnailWidth": 272,
"thumbnailHeight": 480,
"videoWidth": 272,
"videoHeight": 480,
"publicType": 0,
"duration": 10,
"publishTime": 1521107356000,
"featureMask": 0,
"videoItemList": [
{
"id": 4109,
"videoId": 10218,
"resolution": "ld",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-ld/c98dba44b149484f88aa72877d08a07f/4F01D0A5-CC29-4463-8709-6D68AC1A1CD5.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
},
{
"id": 4110,
"videoId": 10218,
"resolution": "sd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-sd/c98dba44b149484f88aa72877d08a07f/4F01D0A5-CC29-4463-8709-6D68AC1A1CD5.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
},
{
"id": 4111,
"videoId": 10218,
"resolution": "hd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-hd/c98dba44b149484f88aa72877d08a07f/4F01D0A5-CC29-4463-8709-6D68AC1A1CD5.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
}
],
"postList": [],
"readCount": 0,
"popularity": 0,
"gcoin": 0,
"postCount": 0,
"giftCount": 0,
"idol": {
"id": 20509,
"userType": "idol",
"gender": "unknown",
"nickname": "专做直播的小姐姐",
"avatar": "http://upload.groupy.vip/avatar/0B77F117-D57E-434F-A9FF-60D1F38C9AEB.jpg",
"sign": "",
"introduce": "hi。\nhey……😈",
"imgs": "",
"levelPlatform": 0,
"dateOfBirth": 927126000000,
"placeOfBirth": "Guangdong Shenzhen🤔",
"bloodType": "A",
"organizationId": 1,
"fansNums": 0,
"followedIdol": false
},
"videoGifts": []
},
{
"id": 10217,
"idolId": 158,
"activityId": 0,
"active": 1,
"title": "2",
"introduce": " ",
"firstFrame": "http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/f455f5d01da148f095af77382e292364/1000.jpg",
"thumbnail": "http://upload.groupy.vip/video_thumbnail/A69EC31D-5FF2-4993-8A81-24417EF34BBE.jpg",
"thumbnailWidth": 272,
"thumbnailHeight": 480,
"videoWidth": 272,
"videoHeight": 480,
"publicType": 0,
"duration": 10,
"publishTime": 1521107247000,
"featureMask": 0,
"videoItemList": [
{
"id": 4106,
"videoId": 10217,
"resolution": "ld",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-ld/f455f5d01da148f095af77382e292364/BEA0FDCC-60EA-42C5-BB26-E59EB533C6EB.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
},
{
"id": 4107,
"videoId": 10217,
"resolution": "hd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-hd/f455f5d01da148f095af77382e292364/BEA0FDCC-60EA-42C5-BB26-E59EB533C6EB.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
},
{
"id": 4108,
"videoId": 10217,
"resolution": "sd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-sd/f455f5d01da148f095af77382e292364/BEA0FDCC-60EA-42C5-BB26-E59EB533C6EB.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
}
],
"postList": [],
"readCount": 0,
"popularity": 0,
"gcoin": 0,
"postCount": 0,
"giftCount": 0,
"idol": {
"id": 158,
"userType": "idol",
"gender": "unknown",
"nickname": "妈妈说名字长一点可以看到一般人看不到的bug😁g",
"avatar": "http://upload.groupy.vip/avatar/F7357D2B-C304-43EB-9796-9824B3E14E2A.jpg",
"sign": "",
"introduce": "",
"imgs": "",
"levelPlatform": 0,
"dateOfBirth": 776962800000,
"bloodType": "Unknown",
"organizationId": 3,
"fansNums": 0,
"followedIdol": false
},
"videoGifts": []
},
{
"id": 10216,
"idolId": 158,
"activityId": 0,
"active": 1,
"title": "参加",
"introduce": " ",
"firstFrame": "http://videodebugoutput.oss-cn-hongkong.aliyuncs.com/Act-Snapshot/5781f5ff83de40b981f90fbb299ba72b/1000.jpg",
"thumbnail": "http://upload.groupy.vip/video_thumbnail/67F05E3B-EC1A-41E1-8DC2-11D924C16038.jpg",
"thumbnailWidth": 272,
"thumbnailHeight": 480,
"videoWidth": 272,
"videoHeight": 480,
"publicType": 0,
"duration": 10,
"publishTime": 1521107209000,
"featureMask": 0,
"videoItemList": [
{
"id": 4103,
"videoId": 10216,
"resolution": "ld",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-ld/5781f5ff83de40b981f90fbb299ba72b/2581A732-12C4-48C7-BB71-723F98C0D7C3.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
},
{
"id": 4104,
"videoId": 10216,
"resolution": "hd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-hd/5781f5ff83de40b981f90fbb299ba72b/2581A732-12C4-48C7-BB71-723F98C0D7C3.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
},
{
"id": 4105,
"videoId": 10216,
"resolution": "sd",
"url": "http://videodebug.groupy.vip/Act-ss-mp4-sd/5781f5ff83de40b981f90fbb299ba72b/2581A732-12C4-48C7-BB71-723F98C0D7C3.mp4",
"width": 272,
"height": 480,
"fps": 25,
"duration": 10,
"filesize": 808752
}
],
"postList": [],
"readCount": 0,
"popularity": 0,
"gcoin": 0,
"postCount": 0,
"giftCount": 0,
"idol": {
"id": 158,
"userType": "idol",
"gender": "unknown",
"nickname": "妈妈说名字长一点可以看到一般人看不到的bug😁g",
"avatar": "http://upload.groupy.vip/avatar/F7357D2B-C304-43EB-9796-9824B3E14E2A.jpg",
"sign": "",
"introduce": "",
"imgs": "",
"levelPlatform": 0,
"dateOfBirth": 776962800000,
"bloodType": "Unknown",
"organizationId": 3,
"fansNums": 0,
"followedIdol": false
},
"videoGifts": []
}
]
}

使用 jq 过滤器

如果想对 json 字符串进行操作, 可以使用 jq 的过滤器;

提取 keys

在做网络爬虫和对接第三方 API 的时候, 经常需要对第三方的 API 返回结果建立对应的 Java Bean, 其中最无聊的操作就是一个一个复制第三方 API 返回的 json 的所有 key , 作为 Java Bean 的字段名, 使用 jqkeys 过滤器可以简化这个无聊的过程:

1
2
3
4
5
6
$ jq 'keys' /tmp/test.json
[
"data",
"errorMsg",
"status"
]

提取一个 key 值

jq 默认将原 json 字符串格式化并原样打印, 如果只对 json 中的一个字段的值感兴趣, 可以在 . 后加字段名, jq 将只打印该字段的值:

1
2
$ jq '.status' /tmp/test.json
200

提取多个 key 值

如果想提取多个 key 值, 可以使用逗号分隔要提取的 key 名称:

1
$ jq '.status, .errorMsg' /tmp/test.json

计算长度 length

有时候为了验证一个接口返回的数据数量是否与预期的一致, 如对于分页接口要验证返回每页数量是否与期望的一致, 可以使用 length 过滤器

  • 如果输入是 json 对象, length 过滤器将计算该对象的 key 数量:
1
2
$ jq 'length' /tmp/test.json
3
  • 如果输入是 json array 数组, length 过滤器计算该数组的元素个数:
1
2
$ jq '.data | length' /tmp/test.json
10

jq 的过滤器同样使用管道符 | 串联多个过滤器, 以上命令先抽取出 data 字段的值 (此处是一个数组), 然后将该值作为过滤器 length 的输入, 所以以上命令计算了 data 字段数组长度;

提取数组所有元素的 key 值

测试 json 文件中 data key 所对应的值是一个 video 对象的数组, 为了提取所有 videotitle 字段, 可以将 “提取 key 值” 的过滤器串联起来使用:

1
$ jq '.data[] | .title' /tmp/test.json

以上命令中, .data 提取出 json 对象的 data 字段, 此时结果是一个 json array 数组, 由于 .key 这种过滤器是提取 json object 对象的 key 值的操作, 因此使用了 [] 将该数组拆分为一个一个的 json object 作为后面 .title 过滤器的输入;

对于连续的 key 值抽取, 可以不使用管道符, 直接串联过滤器, 所以以上命令和以下命令等价:

1
$ jq '.data[].title' /tmp/test.json

为了弄清 [] 的用法, 可以分别执行 jq .data /tmp/test.jsonjq .data[] /tmp/test.json 对比输出结果

以上的命令输出了所有 videotitle 字段值:

1
2
3
4
5
6
7
8
9
10
"可以"
"参加了喔"
"😂"
"hi"
"冷漠"
"页"
"哈哈"
"来了"
"2"
"参加"

使用 jq 函数

对于以上的 test.json 文件, 过滤器 .data[].publishTime 提取出所有视频的发布时间, 但该时间是一个 unix 时间戳, 不方便人阅读, 使用 todate 函数可以将时间戳转换成时间字符串:

1
2
3
4
5
6
7
8
9
10
11
$ jq '.data[].publishTime | todate' /tmp/test.json
"50130-09-04T00:33:20Z"
"50171-12-11T00:30:00Z"
"50171-12-13T18:20:00Z"
"50143-09-17T18:30:00Z"
"50172-02-02T16:16:40Z"
"50171-12-23T18:36:40Z"
"50171-12-22T21:46:40Z"
"50171-12-22T05:06:40Z"
"50171-12-20T22:50:00Z"
"50171-12-20T12:16:40Z"

看到转换后的时间年份非常大, 这是因为 publishTime 字段是精确到毫秒的时间戳, 而 todate 函数是把它当作精确到秒的时间戳来转换的, 为了纠正该错误, 可以使用 jq 的四则运算:

1
2
3
4
5
6
7
8
9
10
11
$ jq '.data[].publishTime / 1000 | todate' /tmp/test.json
"2018-02-28T07:48:02Z"
"2018-03-15T09:33:09Z"
"2018-03-15T09:37:06Z"
"2018-03-05T02:04:57Z"
"2018-03-15T10:50:25Z"
"2018-03-15T09:51:31Z"
"2018-03-15T09:50:16Z"
"2018-03-15T09:49:16Z"
"2018-03-15T09:47:27Z"
"2018-03-15T09:46:49Z"

以上 / 1000publishTime 除以 1000 转换成秒后, 再进行 todate 转换;