[英]Jolt Transformation - pull up and rename field
I am trying to write a jolt transformation with the below input:我正在尝试使用以下输入编写颠簸转换:
{
"data": {
"positions": {
"positionEdge": [
{
"position": {
"ref": "B125AE024:1:BASE",
"catalogue": {
"ref": "BASE:1"
}
},
"cursor": "Y3Vyc29yOi0tLWMxMWYxYWQwLTE2MWEtNDNmNS05ZDM5LWMwODRiZTdiN2Q3OV9fMTY1NzQ5NTU5MTQ4Ng=="
},
{
"position": {
"ref": "B125AE024:2:AGGREGATE",
"catalogue": {
"ref": "ATS:1"
}
},
"cursor": "Y3Vyc29yOi0tLWVmZDgwNTljLWYyNTctNDhhYy1hYzVlLWI3NzlhMjMyMTVmYl9fMTY1NzQ5NTU5MTI3MQ=="
}
],
"pageInfo": {
"hasNextPage": true
}
}
}
}
The expected output is:预期的输出是:
[
{
"ref": "B125AE024:1:BASE",
"catalogueRef": "BASE:1"
},
{
"ref": "B125AE024:2:AGGREGATE",
"catalogueRef": "ATS:1"
}
]
My current spec is:我目前的规格是:
[
{
"operation": "shift",
"spec": {
"data": {
"positions": {
"positionEdge": {
"*": {
"position": {
"@": ".",
"catalogue": {
"ref": "catalogueRef"
}
}
}
}
}
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"catalogue": ""
}
}
}
]
which does not give me the desired result and is missing the catalogueRef of the 2nd record..这没有给我想要的结果,并且缺少第二条记录的 catalogueRef ..
Can the result be achieved in a single transformation, ie rename the catalogue.ref
field up and rename it to catalogueRef
?能否在一次转换中获得结果,即将catalogue.ref
字段重命名并将其重命名为catalogueRef
? I basically want to flatten the position records.我基本上想压平位置记录。
Your help would be much appreciated.非常感谢您的帮助。
Here's the spec to get the desired output这是获得所需输出的规范
[
{
"operation": "shift",
"spec": {
"data": {
"positions": {
"positionEdge": {
"*": {
"position": {
"ref": "[&2].ref",
"catalogue": {
"ref": "[&3].catalogueRef"
}
}
}
}
}
}
}
}
]
the demo on the site http://jolt-demo.appspot.com/ is网站http://jolt-demo.appspot.com/上的演示是
Yes, you can use a single shift transformation spec, by walking through the "positionEdge"
array, in a symbolical manner such as是的,您可以通过以符号方式遍历"positionEdge"
数组来使用单个移位转换规范,例如
[
{
"operation": "shift",
"spec": {
"*": { // stands for the level of the object "data"
"*": { // the level of the object "positions"
"*": { // the level of the array "positionEdge"
"*": { //the indexes of the array "positionEdge"
"position": { // the level of the object "position"
"*": "[#3].&", // going three levels up the tree to reach the level of "positionEdge" by three times traversing the "{" sign, and replicate "ref" attribute
"c*": { //the level of object "catalogue" -- else case
"*": "[#4].&1&" // going four levels up the tree to reach the level of "positionEdge", &1 brings the literal "catalogue", and & already replicates the level from the current level, eg. "ref"
}
}
}
}
}
}
}
}
]
the demo screenshot on the site http://jolt-demo.appspot.com/ ( the famous sandbox of the jolt ) is:网站http://jolt-demo.appspot.com/ (著名的 jolt 沙箱)上的演示屏幕截图是:
If the capital letter R is really needed, then you can convert the leaf node from如果确实需要大写字母R ,那么你可以将叶节点从
"*": "[#4].&1&"
to到
"r*": "[#4].&1R&(0,1)" // where, in &(0,1); zero represents the current level, one represents the 1st occurence for the asterisk, which might be more than one, in order to generate the literal "ef"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.