[英]Jolt transform JSON key/value into String Array
編輯:鍵名是動態的和未知的。
我想要一個 Object 並創建一個字符串數組,其中每個鍵和值連接在一起。
我的鍵包含我需要擺脫的下划線(我有那部分工作)。 我正在努力找出將所有內容結合在一起的下一步。 (我想我錯過了如何從 RHS 引用鍵和值?)
輸入:
{
"object": {
"key_1": [
"A",
"B"
],
"key_2": [
"C"
],
"key_3": [
"D",
"E",
"F"
]
}
}
所需的 Output:
{
"results": [
"key 1: A B",
"key 2: C",
"key 3: D E F"
]
}
規格:
[
{
"operation": "shift",
"spec": {
"object": {
"*_*": "results.&(0,1) &(0,2)",
"*": "results.&"
}
}
}
]
當前規格 output:
{
"results": {
"key 1": [
"A",
"B"
],
"key 2": [
"C"
],
"key 3": [
"D",
"E",
"F"
]
}
}
似乎您需要使用帶有連接函數的修改轉換,以及移位轉換規范,例如
[
{
// combine the components of the each array with one extra whitespaces between them
"operation": "modify-overwrite-beta",
"spec": {
"*": {
"*": "=join(' ',@(1,&))"
}
}
},
{
// get rid of underscores
"operation": "shift",
"spec": {
"*": {
"*_*": "&1.&(0,1) &(0,2)"
}
}
},
{
// generate new arrays with the first components are the keys, and second ones are the values of the previous attributes of the object
"operation": "shift",
"spec": {
"*": {
"*": {
"$": "&",
"@": "&"
}
}
}
},
{
// get concatenated values for key-value pairs with colons between them
"operation": "modify-overwrite-beta",
"spec": {
"*": "=join(': ',@(1,&))"
}
},
{
// get the desired result as a single array
"operation": "shift",
"spec": {
"*": {
"@": "results[]"
}
}
}
]
https://jolt-demo.appspot.com/網站上的演示是:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.