2016-09-20 7 views
1

JOLT変換ライブラリを使用して別の配列にネストされた配列のフィールドの名前を変更します。名前を変更する 1つのフィールドには、名前を変更する 2つのフィールドが、私はワイルドカードを使用してみましたがネストされた配列JOLT変換を使用してネストされた配列のフィールドの名前を変更

の内側にある、アレイ内のトップレベルのフィールドであるが、彼らは私に期待される出力を与えていません。私はJOLT 0.0.22バージョンを使用しています。

入力JSON:

{ 
    "country": "usa", 
    "state": [ 
     { 
      "stateName": "TX", 
      "location": "south", 
      "cities": [ 
       { 
        "name": "Austin", 
        "pop": "1M" 
       }, 
       { 
        "name": "Dallas", 
        "pop": "2M" 
       } 
      ] 
     }, 
     { 
      "stateName": "CA", 
      "location": "west", 
      "cities": [ 
       { 
        "name": "SanFran", 
        "pop": "3M" 
       }, 
       { 
        "name": "LosAngeles", 
        "pop": "4M" 
       } 
      ] 
     } 
    ] 
} 

予想される出力:

{ 
    "country": "usa", 
    "state": [ 
     { 
      "stateName": "TX", 
      "locatedIn": "south", // name change here 
      "cities": [ 
       { 
        "cityname": "Austin", // name change here 
        "citypopulation": "1M" // name change here 
       }, 
       { 
        "cityname": "Dallas", 
        "citypopulation": "2M" 
       } 
      ] 
     }, 
     { 
      "stateName": "CA", 
      "locatedIn": "west", 
      "cities": [ 
       { 
        "cityname": "SanFran", 
        "pop": "3M" 
       }, 
       { 
        "cityname": "LosAngeles", 
        "citypopulation": "4M" 
       } 
      ] 
     } 
    ] 
} 

答えて

2

スペック

[ 
    { 
    "operation": "shift", 
    "spec": { 
     "country": "country", 
     "state": { 
     "*": { // state array index 
      "stateName": "state[&1].stateName", 
      "location": "state[&1].location", 
      "cities": { 
      "*": { // city array index 
       "name": "state[&3].cities[&1].cityname", 
       "pop": "state[&3].cities[&1].citypopualtion" 
      } 
      } 
     } 
     } 
    } 
    } 
] 
関連する問題