【问题标题】:Syntax for JSONPath filtering to not return array不返回数组的 JSONPath 过滤语法
【发布时间】:2022-11-25 16:53:53
【问题描述】:

我是 JSONPath 的新手,想编写一个仅在满足特定条件时才检索属性值的 JSONPath 语法。我所追求的值不是数组的一部分,但我已经设法在以下 JSONPath 工具中进行过滤:https://www.site24x7.com/tools/json-path-evaluator.html

给定以下 JSON,如果 column2.attributeId 等于 B0,我只想提取 column2.dimValue 的值:

{
    "batchId": 279,
    "companyId": "40",
    "period": 202208,
    "taxCode": "1",
    "taxSystem": "",
    "transactionDate": "2022-08-05T00:00:00.000",
    "transactionNumber": 222006089,
    "transactionType": "IF",
    "year": 2022,
    "accountingInformation": {
        "account": "4010",
        "column1": {
            "attributeId": "H9",
            "dimValue": "76"
        },
        "column2": {
            "attributeId": "B0",
            "dimValue": "2170103"
        },
        "column3": {
            "attributeId": "",
            "dimValue": ""
        },
        "column4": {
            "attributeId": "BF",
            "dimValue": "217010330"
        },
        "column5": {
            "attributeId": "10",
            "dimValue": "3101"
        },
        "column6": {
            "attributeId": "06",
            "dimValue": ""
        },
        "column7": {
            "attributeId": "19",
            "dimValue": "K"
        }
    },
    "categories": {
        "cat1": "H9",
        "cat2": "B0",
        "cat3": "",
        "cat4": "BF",
        "cat5": "10",
        "cat6": "06",
        "cat7": "19",
        "dim1": "76",
        "dim2": "2170103",
        "dim3": "",
        "dim4": "217010330",
        "dim5": "3101",
        "dim6": "",
        "dim7": "K"
    },
    "amounts": {
        "amount": 48.24,
        "amount3": 0.0,
        "amount4": 0.0,
        "currencyAmount": 48.24,
        "currencyCode": "NOK",
        "debitCreditFlag": 1
    },
    "invoice": {
        "customerOrSupplierId": "58118",
        "description": "",
        "externalArchiveReference": "",
        "externalReference": "2170103",
        "invoiceNumber": "220238522",
        "ledgerType": "P"
    },
    "additionalInformation": {
        "number": 0,
        "orderLineNumber": 0,
        "orderNumber": 0,
        "sequenceNumber": 1,
        "status": "",
        "value": 0.0,
        "valueDate": "2022-08-05T00:00:00.000"
    },
    "lastUpdated": {
        "updatedAt": "2022-09-05T10:59:11.633",
        "updatedBy": "HELVES"
    }
}

我使用了这个 JSONPath 语法:

$['accountingInformation']['column2'][?(@.attributeId=='B0')].dimValue

这给出了以下结果:

[
   "2170103"
]

我在 Azure 数据工厂映射中使用了这个结果,它似乎不起作用,因为结果是一个数组。

谁能帮我解决它只返回实际值的语法?这可能吗?

【问题讨论】:

  • 如何在 ADF 中映射?你能分享截图吗?

标签: azure jsonpath


【解决方案1】:

我重复了相同的方法,下面是方法。

  • 示例 Json 文件如下图所示作为查找活动的来源。

  • 如果采取activity过滤column2的value with attributeId='B0'。表达式如下 @equals(activity('Lookup1').output.value[0].accountingInformation.column2.attributeId ,'B0')

  • 在真实情况下中频活动,设置变量被添加。采用字符串类型的新变量,并使用以下表达式进行设置。 @activity('Lookup1').output.value[0].accountingInformation.column2.dimvalue

  • 然后将复制活动添加到 IF 活动旁边。在源中采用虚拟数据集。+新在附加列中单击

名称:col1 值:@variables('v2')

  • 在映射中,导入模式被点击。除了在源中添加的附加列之外的所有其他列都将被删除。

  • 管道已调试,数据已无误地复制到接收器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-26
    • 1970-01-01
    • 1970-01-01
    • 2022-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多