我是JOLT转换的新手,我发现它在JSON转换中非常有用。但是当我遇到嵌套且复杂的JSON时,我感到困惑。
下面的JSON是一个嵌套且复杂的JsonArray,我需要将其转换为完全扁平的JsonArray。
JSON输入:
[
{
"Code": -1,
"Name": "All",
"PublisherTypes": [
{
"Code": 2,
"Name": "General",
"LetterTypes": []
},
{
"Code": 3,
"Name": "Financials",
"LetterTypes": []
}
]
},
{
"Code": 1,
"Name": "Information",
"PublisherTypes": [
{
"Code": 2,
"Name": "General",
"LetterTypes": [
{
"Id": 10,
"Name": "Long Term Info",
"Code": ""
},
{
"Id": 20,
"Name": "Short Term Info",
"Code": ""
}
]
},
{
"Code": 3,
"Name": "Financials",
"LetterTypes": [
{
"Id": 101,
"Name": "Total Income",
"Code": ""
},
{
"Id": 202,
"Name": "Total Taxes",
"Code": ""
}
]
}
]
},
{
"Code": 2,
"Name": "Reporting",
"PublisherTypes": [
{
"Code": 2,
"Name": "General",
"LetterTypes": [
{
"Id": 8,
"Name": "Monthly Reoprt",
"Code": ""
},
{
"Id": 58,
"Name": "Status Report",
"Code": ""
}
]
},
{
"Code": 3,
"Name": "Financials",
"LetterTypes": [
{
"Id": 170,
"Name": "Manager Level",
"Code": ""
},
{
"Id": 156,
"Name": "Expert Level",
"Code": ""
}
]
}
]
}
]
如您所见,我们有一个空的对象“字母类型”:[],但在其他Json对象中,“字母类型”有自己的对象并且不是空的。
下面的JSON是我的预期输出。
预期输出:
[
{
"Code": -1,
"Name": "All",
"PublisherCode": 2,
"PublisherName": "General",
"LetterId": "",
"LetterName": "",
"LetterCode": ""
},
{
"Code": -1,
"Name": "All",
"PublisherCode": 3,
"PublisherName": "Financials",
"LetterId": "",
"LetterName": "",
"LetterCode": ""
},
{
"Code": 1,
"Name": "Information",
"PublisherCode": 2,
"PublisherName": "General",
"LetterId": 10,
"LetterName": "Long Term Info",
"LetterCode": ""
},
{
"Code": 1,
"Name": "Information",
"PublisherCode": 2,
"PublisherName": "General",
"LetterId": 20,
"LetterName": "Short Term Info",
"LetterCode": ""
},
{
"Code": 1,
"Name": "Information",
"PublisherCode": 3,
"PublisherName": "Financials",
"LetterId": 101,
"LetterName": "Total Income",
"LetterCode": ""
},
{
"Code": 1,
"Name": "Information",
"PublisherCode": 3,
"PublisherName": "Financials",
"LetterId": 202,
"LetterName": "Total Taxes",
"LetterCode": ""
},
{
"Code": 2,
"Name": "Reporting",
"PublisherCode": 2,
"PublisherName": "General",
"LetterId": 8,
"LetterName": "Monthly Reoprt",
"LetterCode": ""
},
{
"Code": 2,
"Name": "Reporting",
"PublisherCode": 2,
"PublisherName": "General",
"LetterId": 58,
"LetterName": "Status Reoprt",
"LetterCode": ""
},
{
"Code": 2,
"Name": "Reporting",
"PublisherCode": 3,
"PublisherName": "Financials",
"LetterId": 170,
"LetterName": "Manager Level",
"LetterCode": ""
},
{
"Code": 2,
"Name": "Reporting",
"PublisherCode": 3,
"PublisherName": "Financials",
"LetterId": 156,
"LetterName": "Expert Level",
"LetterCode": ""
}
]
我需要的是一个JOLT规范来为我生成上述输出,以便当“LetterTypes”为空时,它在输出中显示为空字符串("")值。那么,有人能为这个问题提供一个JOLT规范吗?
您可以在应用修改转换规范后使用以下移位转换,其中;
“12”-
,以便为
LetterType
数组的每个属性使用默认null(“”)
值填充空数组,例如
json prettyprint-override">[
{
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": {
"*": {
"Letter*": ["=toInteger",
[
{
"Id": "",
"Name": "",
"Code": ""
}
]
]
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*Types": { // * wildcard represents one or multiple characters, here "*Types" stands for "PublisherTypes"
"*": {
"*Types": {
"*": {
"@(4,Code)": "Code",
"@(4,Name)": "Name", // going 4 levels up to grab the desired value
"@(2,Code)": "PublisherCode",
"@(2,Name)": "PublisherName", // going 2 levels up to grab the desired value
"*": "&(2,1)&" // all attributes under the "LetterTypes" arrays, in &(2,1)& : 2 is for going 2 levels up, 1 represents grabbing the piece("Letter") where * is substituted, and the last & represents the value of the current key name("Code" or "Name")
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"*": {
"*": {
"@": "[&].&2"
}
}
}
}
]
所有的属性都累积在最里面的部分,在这个部分中,在整个JSON值中重复次数最多。
在第一个规范中,确定了包含10个组件的所有单个数组,并将它们移动到第二个规范中的相应对象。
我有一个嵌套的JSON对象,如下所示: 我想将其转换为: 我如何使用JOLT实现这一点?感谢您的参与。
我有一个关于使用jolt将平面json转换成嵌套json的问题。我对jolt很陌生,这是我的意见 我编写了jolt spec,但我没有得到想要的输出 我的预期产出是: 任何震动专家都可以帮助我获得所需的输出。我应该在颠簸中使用多个变换,还是可以在一个震动变压器中获得所需的输出?
我只想扁平化嵌套JSON的属性,但仍然适用于输入数组中的所有对象 很难将这三个字段放在一个规范中(类型字段、geo字段、properties字段)。我编写了规范来单独完成每一个操作,但是当我将这些规范组合在一个对象中使用时,它会产生错误的输出--对象数组真的把它搞砸了。 期望输出:
我试图根据第二个嵌套数组中的值的数量将嵌套数组转换为对象。我似乎无法获取值字段的数量并将其用作规范中的键。现在这是我的输入JSON文件: 这是我想要的JSON输出: 这是我目前的规格 有人有类似的情况吗?
所以目前我看到的是这样的: 这是我目前编写的Jolt规范(编辑): 以及转换后的输出: 任何帮助都是非常感谢的。
我希望Jolt将一个复杂的json转换为下面所需的json。 输入JSON: 输出量的希望值 我试过遵循Jolt Spec 但得到了以下输出 因此,正如所见,除了最后一个级别值之外,所有其他值都具有具有重复值的数组。任何人都可以帮助解决 Jolt 规范中缺失或错误的地方吗?