0

这就是我想要做的: 1. 将名字和姓氏与名字连接起来 2. 将 id 更改为 employeeID 并添加员工 ID 的前缀:emp_id 3. 如果部门等于销售,则部门应该是“SL” 4. 如果部门等于销售额,比部门应该是“RET”

这是我的输入:

{
    "employees": [{
            "f_name": "tom",`
            "l_name": "smith",
            "id": "100",
            "department": "sales",
            "company": "ABC Intelligence"
        },

        {
            "f_name": "john",
            "l_name": "doe",
            "id": "102",
            "department": "returns",
            "company": "ABC Intelligence"
        }, {
            "f_name": "jane",
            "l_name": "doe",
            "id": "103",
            "department": "sales",
            "company": "ABC Intelligence"
        }
    ]
}

specs:
 [{
    "operation": "shift",
    "spec": {
        "employees": {
            "*": {

                "name": "=concat(@(1,f_name),' ',@(1,l_name))"


            }
        }
    }

},
 {
   "operation": "remove",
    "spec": {
      "employees": {
        "*": { 
          "f_name": "",
          "l_name": ""

      }
    }
  }
 }
]


desired output:

{
    "employees": [
        {
            "name": "tom smith",
            "employeeID": "emp_100",
            "department": "SL",
            "company": "ABC Intelligence"
        },
        {
            "name": "john doe",
            "employeeID": "emp_102",
            "department": "RET",
            "company": "ABC Intelligence"
        },
        {
            "name": "jane doe",
            "employeeID": "emp_103",
            "department": "SL",
            "company": "ABC Intelligence"
        }
    ]
}

我能够获得第一条规则,但仍在与其他规则作斗争。任何帮助,将不胜感激

4

1 回答 1

0

规格

[
  {
    "operation": "modify-default-beta",
    "spec": {
      // add the mapping of department name to code, so we can use it later
      "deptMap": {
        "sales": "SL",
        "returns": "RET"
      },
      "employees": {
        "*": {
          // build the fullName from the first and last names
          "name": "=concat(@(1,f_name),' ',@(1,l_name))",
          // build the employeeID
          "employeeID": "=concat(emp_,@(1,id))"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "employees": {
        "*": { // employees arrays
          // pass name, company, and employeeID thru
          "name": "employees[&1].name",
          "company": "employees[&1].company",
          "employeeID": "employees[&1].employeeID",
          // lookup the deparment code
          "department": {
            "*": { // value of dept
              // got up 5 levels, come back down the deptMap
              "@(4,deptMap.&)": "employees[&3].department"
            }
          }
        }
      }
    }
  }
]
于 2017-03-03T02:30:55.380 回答