2017-01-21 67 views
0

我試圖具有映射到陣列的鍵值對,使用顛簸變換規格的Json變換以嵌套陣列

輸入JSON區分各個值作爲類型

{ 
"testurl": "someurl", 
"website": "someurl2" 
} 

嘗試這樣做規範

[ 
    { 
    "operation": "shift", 
    "spec": { 
     "testurl": "Urls[].testurl", 
     "website": "Urls[].website" 
    } 
    }, 
    { 
    "operation": "shift", 
    "spec": { 
     "Urls": { 
     "*": { 
      "$": "Urls[&1].val"  
     } 
     } 
    } 
    } 
] 

預期的結果是這樣

{ 
     "Urls": [{ 
      "url": "someurl", 
      "val": "testurl" 
     }, { 
      "url": "someurl2", 
      "val": "website" 

     }] 
    } 
+0

@Milo是你能回答這個https://stackoverflow.com/questions/44144846/json-jolt-shift-specification-for-duplicate-keys-with-different-value-類型 –

回答

3

是的,您可以將一組Json鍵值對轉換爲數組。

它需要2班才能安全。

1st shift隔離您想要變成數組的所有屬性。

2nd shift能夠使用「*」來匹配所有這些項目並將它們放入一個數組中。

規格

[ 
    { 
    "operation": "shift", 
    "spec": { 
     "testurl": "temp.testurl", 
     "website": "temp.website" 
    } 
    }, 
    { 
    "operation": "shift", 
    "spec": { 
     "temp": { 
     "*": { 
      "$": "Urls[#2].val", 
      "@": "Urls[#2].url" 
     } 
     } 
    } 
    } 
] 
+0

非常感謝,這工作! 這個框架真是太神奇了.. –