json - 检查数组是否为空或不颠簸转换
问题描述
我的输入如下
{
"reports": [
{
"fromDate": "2020-06-01T00:00:00",
"toDate": "2021-45-31T00:00:00",
"cashReceipts": {
"accountId": "cashReceipts",
"name": "Cash Receipts",
"value": 5080.27,
"items": [
{
"accountId": "income",
"name": "Income",
"value": 3113.32,
"items": []
},
{
"accountId": "accountsReceivable",
"name": "Accounts Receivable",
"value": 1966.95,
"items": [
{
"accountId": "cashreceivable",
"name": "cash",
"value": 500.0,
"items": []
},
{
"accountId": "chequereceivalbe",
"name": "Check",
"value": 1466.95,
"items": []
}
]
}
]
},
"cashPayments": {
"accountId": "cashPayments",
"name": "Cash Payments",
"value": 6984.39,
"items": [
{
"accountId": "expenses",
"name": "Expenses",
"value": 6755.64,
"items": []
},
{
"accountId": "costOfSales",
"name": "Cost of Sales",
"value": 228.75,
"items": []
}
]
}
}
],
"reportBasis": "Cash",
"reportInput": "Direct",
"currency": "USD",
"mostRecentAvailableMonth": "2021-05-31T00:00:00",
"earliestAvailableMonth": "2019-06-01T00:00:00"
}
我需要如下输出
[
{
"currency": "USD",
"accountType" : "cashReceipts",
"accountId": "income",
"accountName": "Income",
"balance": 3113.32
},
{
"currency": "USD",
"accountType" : "cashReceipts",
"accountId": "cashreceivable",
"accountName": "cash",
"balance": 500.0
},
{
"currency": "USD",
"accountType" : "cashReceipts",
"accountId": "chequereceivalbe",
"accountName": "Check",
"balance": 1466.95
},
{
"currency": "USD",
"accountType" : "cashPayments",
"accountId": "expenses",
"accountName": "Expenses",
"balance": 6755.64
},
{
"currency": "USD",
"accountType" : "cashPayments",
"accountId": "costOfSales",
"accountName": "Cost of Sales",
"balance": 228.75
}
]
我使用了 jolt 规格作为
[
{
"operation": "modify-default-beta",
"spec": {
"reports": {
"*": {
"cashReceipts": {
"accountName": "@(1,name)",
"fromDate": "@(2,fromDate)",
"creationTime": "@(2,toDate)",
"currency": "@(4,currency)",
"reportBasis": "@(4,reportBasis)",
"accountType": "income",
"balance": "@(1,value)",
"bankingDate": "@(2,date)",
"items": {
"*": {
"balance": "@(1,value)",
"bankingDate": "@(2,toDate)",
"accountName": "@(1,name)",
"creationTime": "@(2,date)",
"currency": "@(6,currency)",
"accountType": "Cash Receipts"
}
}
},
"cashPayments": {
"items": {
"*": {
"balance": "@(1,value)",
"bankingDate": "@(2,toDate)",
"accountName": "@(1,name)",
"creationTime": "@(2,date)",
"currency": "@(6,currency)",
"accountType": "Cash Payments"
}
}
}
}
}
}
},
{
"operation": "shift",
"spec": {
"reports": {
"*": {
"cashReceipts|cashPayments": {
"items": {
"*": "[]"
}
}
}
}
}
},
{
"operation": "remove",
"spec": {
"*": {
"name": "",
"value": ""
},
"value": ""
}
}
]
我想导出最后一个项目。但有时它可能只出现在一个级别,有时它可能出现在 2 到 3 级。如果您看到“cashReceipts”:和“cashPayments”项目之间的差异:数据意味着您可以理解差异。
需要迭代到我的项目是空的。但它可能会有所不同
解决方案
推荐阅读
- c++ - 为什么我收到 QWindowsWindow::setGeometry: Unable to set geometry warning with Qt 5.12.0
- node.js - 如何通过 keycloak 服务帐户登录?
- javascript - 显示数组值(如果数组名和字符串名相同)
- php - Google Places Photo API 返回一张图片,但是我不知道如何将它发送到我的前端
- python - 将 Canny 边缘检测转换为 np.array
- jdbc - 当我使用相同的密钥时,Kafka JDBC 连接不会将消息发布到一个分区
- java - 在java中解析xml时跳过元素的反序列化并将整个内容作为字符串获取
- python - 无法调用“按钮”命令:应用程序已被销毁
- java - 在 lambda 表达式中设置变量
- yocto - Yocto:在 etcdir 中创建一个新目录