如何根据其值分割和分组json数据?

时间:2018-02-08 02:38:25

标签: javascript json

我不知道如何正确描述我的问题,所以我会反过来证明,

我有这个json数据,一个从excel文件中提取的数据,其中每个员工的工资单信息都列在excel文件中,

我想为每位员工提取该数据,

我的第一步是将excel文件转换为json数据,

我使用sheetjs将excel文件转换为json,

这是excel文件, enter image description here

这是我从提取中获得的json。

"Payslip": [

    [
      "Name: Employee1",
      null,
    ],
    [
      "Earnings",
      "Amount",
      "Deductions",
      "Amount",
      "Take Home"
    ],
    [
      "Regular",
      "2,500.00",
      "Coop Loan",
      "1,500.00"
    ],
    [
      "Overtime",
      "1,500.00",
      "Tax",
      "2,200.00"
    ],
    [
      "Holidays",
      "700.00"
    ],
    [
      "Bonus",
      "1,000.00"
    ],
    [
      null,
      "5,700.00",
      null,
      "3,700.00",
      "2,000.00"
    ],
    [
      "Name/Signature/Role/Date: ",
      null,
      "Officer Name"
    ],

     [
      "Name: Employee2",
      null,
    ],
    [
      "Earnings",
      "Amount",
      "Deductions",
      "Amount",
      "Take Home"
    ],
    [
      "Regular",
      "3,500.00",
      "Coop Loan",
      "1,300.00"
    ],
    [
      "Overtime",
      "1,500.00",
      "Tax",
      "2,200.00"
    ],
    [
      "Holidays",
      "700.00"
    ],
    [
      "Bonus",
      "1,000.00"
    ],
    [
      null,
      "5,700.00",
      null,
      "3,700.00",
      "2,000.00"
    ],
    [
      "Name/Signature/Role/Date: ",
      null,
      "Officer Name"
    ],

     [
      "Name: Employee3",
      null,
    ],
    [
      "Earnings",
      "Amount",
      "Deductions",
      "Amount",
      "Take Home"
    ],
    [
      "Regular",
      "2,500.00",
      "Coop Loan",
      "4,500.00"
    ],
    [
      "Overtime",
      "1,500.00",
      "Tax",
      "2,200.00"
    ],
    [
      "Holidays",
      "700.00"
    ],
    [
      "Bonus",
      "1,000.00"
    ],
    [
      null,
      "5,700.00",
      null,
      "3,700.00",
      "2,000.00"
    ],
    [
      "Name/Signature/Role/Date: ",
      null,
      "Officer Name"
    ]
]

现在我的问题是我如何对每个员工的json数据进行分组,

输出应该是这样的,

{
    "title": "Requirements List",
    "employees": 
        [
            {
                "name": "Employee1",
                "earnings": 
                    [
                        {
                            "title": "Holiday"
                            "amount": "1,500.00"
                        },
                        {
                            "title": "Regular"
                            "amount": "2,500.00"
                        }
                    ],
                "deductions": 
                    [
                        {
                            "title": "Loan",
                            "amount": "500.00"
                        }
                    ],
                "total_earnings": "4,000.00",
                "total_deductions": "500.00",
                "take_home": "3,500.00"
            },
            {
                "name": "Employee2",
                "earnings": 
                    [
                        {
                            "title": "Holiday"
                            "amount": "2,500.00"
                        },
                        {
                            "title": "Regular"
                            "amount": "3,500.00"
                        }
                    ],
                "deductions": 
                    [
                        {
                            "title": "Loan",
                            "amount": "1500.00"
                        }
                    ],
                "total_earnings": "5,000.00",
                "total_deductions": "1500.00"
                "take_home": "3,500.00"
            }
        ]
}

我想知道如何为每个用户提取数据?

谢谢,

你知道我能达到目标的任何其他方式吗,谢谢你,

0 个答案:

没有答案