Arrays 使用JOLT将顶级字段下推到数组的每个元素中

Arrays 使用JOLT将顶级字段下推到数组的每个元素中,arrays,json,jolt,Arrays,Json,Jolt,我正在努力将顶级字段下推到数组中的每个元素中 我想把'country'放入'state'数组的每个元素中 我想将“stateName”放入“cities”数组的每个元素中 输入JSON: { "country": "usa", "state": [ { "stateName": "TX", "location": "south", "cities": [ {

我正在努力将顶级字段下推到数组中的每个元素中

  • 我想把'country'放入'state'数组的每个元素中
  • 我想将“stateName”放入“cities”数组的每个元素中
  • 输入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"
                    }
                ]
            }
        ]
    }
    
    预期输出JSON:

    {
        "state": [
            {
                "country": "usa",      // pushed down country field into state array
                "stateName": "TX",
                "location": "south",
                "cities": [
                    {
                        "stateName": "TX",   // pushed down stateName field into cities array
                        "name": "Austin",
                        "pop": "1M"
                    },
                    {
                        "stateName": "TX",
                        "name": "Dallas",
                        "pop": "2M"
                    }
                ]
            },
            {
                "country": "usa",
                "stateName": "CA",
                "location": "west",
                "cities": [
                    {
                        "stateName": "CA",
                        "name": "SanFran",
                        "pop": "3M"
                    },
                    {
                        "stateName": "CA",
                        "name": "LosAngeles",
                        "pop": "4M"
                    }
                ]
            }
        ]
    }
    
    规格


    我有一个类似的问题,但目的不同@米洛斯,你有什么见解吗?这是:
    [
      {
        "operation": "shift",
        "spec": {
          "state": {
            "*": { // state array index
              "stateName": "state[&1].stateName",
              "location": "state[&1].location",
              // got up the tree 3 level 0,1,2 
              //  and grab the value of "country" from
              //  that top level, and write it out to
              //  state[&1].country
              "@(2,country)": "state[&1].country",
              "cities": {
                "*": { // city array index
                  "name": "state[&3].cities[&1].name",
                  "pop": "state[&3].cities[&1].pop",
                  "@(2,stateName)": "state[&3].cities[&1].stateName"
                }
              }
            }
          }
        }
      }
    ]