我从eurostat获得了一些json,它看起来像这样:
{
"version": "2.0",
"label": "Principaux agrégats des administrations publiques, y compris recettes et dépenses",
"href": "http://ec.europa.eu/eurostat/wdds/rest/data/v2.1/json/fr/gov_10a_main?unit=PC_GDP&na_item=TE§or=S13&time=2008&time=2009&time=2010&time=2011&time=2012&time=2013&time=2014&time=2015&time=2016&time=2017&geo=DE&geo=AT&geo=BE&geo=BG&geo=CY&geo=HR&geo=FI",
"source": "Eurostat",
"updated": "2018-10-26",
"status": {
"57": "b"
},
"extension": {
"datasetId": "gov_10a_main",
"lang": "FR",
"description": null,
"subTitle": null,
"status": {
"label": {
"b": "rupture de série"
}
}
},
"class": "dataset",
"value": {
"0": 49.9,
"1": 54.1,
"2": 52.8,
"3": 50.9,
"4": 51.2,
"5": 51.6,
"6": 52.4,
"7": 51.1,
"8": 50.3,
"9": 49.2,
"10": 50.3,
"11": 54.2,
"12": 53.3,
"13": 54.5,
"14": 55.9,
"15": 55.8,
"16": 55.3,
"17": 53.7,
"18": 53,
"19": 52.2,
"20": 37.1,
"21": 39.4,
"22": 36.2,
"23": 33.8,
"24": 34.5,
"25": 37.7,
"26": 43.1,
"27": 40.5,
"28": 35.1,
"29": 35.1,
"30": 38.4,
"31": 42.1,
"32": 42,
"33": 42.3,
"34": 41.9,
"35": 41.9,
"36": 48.8,
"37": 40.6,
"38": 38,
"39": 37.5,
"40": 43.6,
"41": 47.6,
"42": 47.3,
"43": 44.7,
"44": 44.3,
"45": 44.7,
"46": 44,
"47": 43.7,
"48": 43.9,
"49": 43.9,
"50": 48.3,
"51": 54.8,
"52": 54.8,
"53": 54.4,
"54": 56.2,
"55": 57.5,
"56": 58.1,
"57": 57.1,
"58": 55.9,
"59": 54,
"60": 45.3,
"61": 48.3,
"62": 48,
"63": 48.5,
"64": 47.8,
"65": 47.6,
"66": 48.1,
"67": 48.3,
"68": 46.9,
"69": 45
},
"dimension": {
"unit": {
"label": "unit",
"category": {
"index": {
"PC_GDP": 0
},
"label": {
"PC_GDP": "Pourcentage du produit intérieur brut (PIB)"
}
}
},
"sector": {
"label": "sector",
"category": {
"index": {
"S13": 0
},
"label": {
"S13": "Administrations publiques"
}
}
},
"na_item": {
"label": "na_item",
"category": {
"index": {
"TE": 0
},
"label": {
"TE": "Total des dépenses des administrations publiques"
}
}
},
"geo": {
"label": "geo",
"category": {
"index": {
"AT": 0,
"BE": 1,
"BG": 2,
"CY": 3,
"DE": 4,
"FI": 5,
"HR": 6
},
"label": {
"AT": "Autriche",
"BE": "Belgique",
"BG": "Bulgarie",
"CY": "Chypre",
"DE": "Allemagne (jusqu'en 1990, ancien territoire de la RFA)",
"FI": "Finlande",
"HR": "Croatie"
}
}
},
"time": {
"label": "time",
"category": {
"index": {
"2008": 0,
"2009": 1,
"2010": 2,
"2011": 3,
"2012": 4,
"2013": 5,
"2014": 6,
"2015": 7,
"2016": 8,
"2017": 9
},
"label": {
"2008": "2008",
"2009": "2009",
"2010": "2010",
"2011": "2011",
"2012": "2012",
"2013": "2013",
"2014": "2014",
"2015": "2015",
"2016": "2016",
"2017": "2017"
}
}
}
},
"id": [
"unit",
"sector",
"na_item",
"geo",
"time"
],
"size": [
1,
1,
1,
7,
10
]
}
我想生成一个csv文件。
首先,我需要通过字符串将.status与.value连接起来(很抱歉,我对json的了解不足)->“ status”:{“ 57”:“ b”}与“ value”:{“ 57”: 57.1}。
第二,我需要生成与原始表相同的表(从eurostat下载)。
我尝试了许多jq命令,例如:
.status,.value | to_entries
我远远没有找到解决方案。
有帮助吗?我认为需要map或map_values / group_by命令,但我不太了解这些功能。
编辑:
我从eurostat下载数据。
我使用他们的网络服务here,可以在其中下载json格式的数据。
我想用jq在外壳中复制与原始表相同的表。以我为例,它应该像:
GEO / TIME,2010、2011、2012、2013、2014、2015、2016、2017 比利时文,“ 53,3”,“ 54,5”,“ 55,9”,“ 55,8”,“ 55,3”,“ 53,7”,“ 53,0”,“ 52,2” 保加利亚语,“ 36,2”,“ 33,8”,“ 34,5”,“ 37,7”,“ 43,1”,“ 40,5”,“ 35,1”,“ 35,1” “ Allemagne(1990年十月,RFA的旧领土)”,“ 47,3”,“ 44,7”,“ 44,3”,“ 44,7”,“ 44,0”,“ 43,7 “,” 43,9“,” 43,9“ 克罗地亚语,“ 48,0”,“ 48,5”,“ 47,8”,“ 47,6”,“ 48,1”,“ 48,3”,“ 46,9”,“ 45,0” Chypre,“ 42,0”,“ 42,3”,“ 41,9”,“ 41,9”,“ 48,8”,“ 40,6”,“ 38,0”,“ 37,5” Finlande,“ 54,8”,“ 54,4”,“ 56,2”,“ 57,5”,“ 58,1”,“ 57,1”,“ 55,9”,“ 54,0” < / p>
但是json包含元数据,并且Finlande的值必须为57,1b。
我希望通过此编辑可以使它更加清晰。
非常感谢您的帮助。
答案 0 :(得分:0)
您的问题并不能非常准确地表明您想要什么输出,但是希望您能够适应以下要求:
.value as $dict
| .status
| to_entries
| map( [.key, .value, $dict[.key]] )
| .[]
| @csv
使用您的输入,并使用-r选项调用jq,将产生:
"57","b",57.1