JOLT 规范 - 将数组转置为 Class
JOLT Spec - Transpose Array to Class
我需要使用 JOLT 规范转换 JSON 结构。
我使用 https://jolt-demo.appspot.com 来测试下面的内容。
我也可以通过另一个 JOLT 规范 运行 输出,然后检索我需要的 JSON 输出,但我仍然不知道 JOLT 规范应该是什么样子,我看过在示例中,并没有更接近上面提到的内容。
输入 -> 变换 -> 输出
这是输入 JSON
{
"result": 0,
"companys": [
{
"id": 3,
"pId": 322,
"nm": "Balfin Trading (PTY) LTD"
},
{
"id": 25,
"pId": 0,
"nm": "FootCam"
}
],
"vehicles": [
{
"id": 487,
"desc": null,
"ic": 2,
"nm": "GCS001",
"pnm": null,
"dl": [
{
"id": "60335",
"ic": 0,
"us": null,
"md": 361,
"tn": "",
"vt": null,
"io": "",
"isb": null,
"sim": "0726168807",
"cc": 4,
"dId": null,
"sdc": null,
"pid": 83,
"st": null,
"tc": 0,
"cn": "ROAD,CAB,R SIDE VIEW,L SIDE VIEW",
"nflt": null
}
],
"adt": null,
"pvg": null,
"djb": null,
"etm": null,
"pid": 83,
"phone": null,
"abbr": null,
"vtp": null,
"st": null,
"dt": null,
"dn": null,
"linesOperation": null
},
{
"id": 486,
"desc": null,
"ic": 2,
"nm": "GCS002",
"pnm": null,
"dl": [
{
"id": "60334",
"ic": 0,
"us": null,
"md": 361,
"tn": "",
"vt": null,
"io": "",
"isb": null,
"sim": "0767024106",
"cc": 4,
"dId": null,
"sdc": null,
"pid": 83,
"st": null,
"tc": 0,
"cn": "ROAD,CAB,R SIDE,L SIDE",
"nflt": null
}
],
"adt": null,
"pvg": null,
"djb": null,
"etm": null,
"pid": 83,
"phone": null,
"abbr": null,
"vtp": null,
"st": null,
"dt": null,
"dn": null,
"linesOperation": null
},
{
"id": 491,
"desc": null,
"ic": 2,
"nm": "GCS003",
"pnm": null,
"dl": [
{
"id": "60294",
"ic": 0,
"us": null,
"md": 361,
"tn": "",
"vt": null,
"io": "",
"isb": null,
"sim": "0795732047",
"cc": 4,
"dId": null,
"sdc": null,
"pid": 83,
"st": null,
"tc": 0,
"cn": "ROAD,CAB,R SIDE,L SIDE",
"nflt": null
}
],
"adt": null,
"pvg": null,
"djb": null,
"etm": null,
"pid": 83,
"phone": null,
"abbr": null,
"vtp": null,
"st": null,
"dt": null,
"dn": null,
"linesOperation": null
}
]
}
这是我目前拥有的 JOLT 规格
[
{
"operation": "shift",
"spec": {
"vehicles": {
"*": {
"nm": "name",
"dl": {
"*": {
"id": "deviceID"
}
}
}
}
}
}
]
给出以下输出
{
"name" : [ "GCS001", "GCS002", "GCS003" ],
"deviceID" : [ "60335", "60334", "60294" ]
}
相反,我需要输出
[{
"name" : "GCS001",
"deviceID" : "60335"
},
{
"name" : "GCS002",
"deviceID" : "60334"
},
{
"name" : "GCGCS003S001",
"deviceID" : "60294"
}]
你们非常亲密。我所做的 - 将 name 和 deviceId 放入 t 对象,在另一个规范中我删除了这个对象的名称。
[
{
"operation": "shift",
"spec": {
"vehicles": {
"*": {
"nm": "t[&1].name",
"dl": {
"*": {
"id": "t[&3].deviceID"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"t": ""
}
}
]
[
{
"operation": "shift",
"spec": {
"vehicles" : {
"*" : {
"@(0,nm)" : "[&1].name",
"dl" : {
"*" : {
"@(0,id)" : "[&3].deviceID"
}
}
}
}
}
}
]
我需要使用 JOLT 规范转换 JSON 结构。 我使用 https://jolt-demo.appspot.com 来测试下面的内容。
我也可以通过另一个 JOLT 规范 运行 输出,然后检索我需要的 JSON 输出,但我仍然不知道 JOLT 规范应该是什么样子,我看过在示例中,并没有更接近上面提到的内容。
输入 -> 变换 -> 输出
这是输入 JSON
{
"result": 0,
"companys": [
{
"id": 3,
"pId": 322,
"nm": "Balfin Trading (PTY) LTD"
},
{
"id": 25,
"pId": 0,
"nm": "FootCam"
}
],
"vehicles": [
{
"id": 487,
"desc": null,
"ic": 2,
"nm": "GCS001",
"pnm": null,
"dl": [
{
"id": "60335",
"ic": 0,
"us": null,
"md": 361,
"tn": "",
"vt": null,
"io": "",
"isb": null,
"sim": "0726168807",
"cc": 4,
"dId": null,
"sdc": null,
"pid": 83,
"st": null,
"tc": 0,
"cn": "ROAD,CAB,R SIDE VIEW,L SIDE VIEW",
"nflt": null
}
],
"adt": null,
"pvg": null,
"djb": null,
"etm": null,
"pid": 83,
"phone": null,
"abbr": null,
"vtp": null,
"st": null,
"dt": null,
"dn": null,
"linesOperation": null
},
{
"id": 486,
"desc": null,
"ic": 2,
"nm": "GCS002",
"pnm": null,
"dl": [
{
"id": "60334",
"ic": 0,
"us": null,
"md": 361,
"tn": "",
"vt": null,
"io": "",
"isb": null,
"sim": "0767024106",
"cc": 4,
"dId": null,
"sdc": null,
"pid": 83,
"st": null,
"tc": 0,
"cn": "ROAD,CAB,R SIDE,L SIDE",
"nflt": null
}
],
"adt": null,
"pvg": null,
"djb": null,
"etm": null,
"pid": 83,
"phone": null,
"abbr": null,
"vtp": null,
"st": null,
"dt": null,
"dn": null,
"linesOperation": null
},
{
"id": 491,
"desc": null,
"ic": 2,
"nm": "GCS003",
"pnm": null,
"dl": [
{
"id": "60294",
"ic": 0,
"us": null,
"md": 361,
"tn": "",
"vt": null,
"io": "",
"isb": null,
"sim": "0795732047",
"cc": 4,
"dId": null,
"sdc": null,
"pid": 83,
"st": null,
"tc": 0,
"cn": "ROAD,CAB,R SIDE,L SIDE",
"nflt": null
}
],
"adt": null,
"pvg": null,
"djb": null,
"etm": null,
"pid": 83,
"phone": null,
"abbr": null,
"vtp": null,
"st": null,
"dt": null,
"dn": null,
"linesOperation": null
}
]
}
这是我目前拥有的 JOLT 规格
[
{
"operation": "shift",
"spec": {
"vehicles": {
"*": {
"nm": "name",
"dl": {
"*": {
"id": "deviceID"
}
}
}
}
}
}
]
给出以下输出
{
"name" : [ "GCS001", "GCS002", "GCS003" ],
"deviceID" : [ "60335", "60334", "60294" ]
}
相反,我需要输出
[{
"name" : "GCS001",
"deviceID" : "60335"
},
{
"name" : "GCS002",
"deviceID" : "60334"
},
{
"name" : "GCGCS003S001",
"deviceID" : "60294"
}]
你们非常亲密。我所做的 - 将 name 和 deviceId 放入 t 对象,在另一个规范中我删除了这个对象的名称。
[
{
"operation": "shift",
"spec": {
"vehicles": {
"*": {
"nm": "t[&1].name",
"dl": {
"*": {
"id": "t[&3].deviceID"
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"t": ""
}
}
]
[
{
"operation": "shift",
"spec": {
"vehicles" : {
"*" : {
"@(0,nm)" : "[&1].name",
"dl" : {
"*" : {
"@(0,id)" : "[&3].deviceID"
}
}
}
}
}
}
]