You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求正确JSON Path:通过name/description定位提取指定JSON的value值

Fixing Your JSON Path to Extract the "500" Value

Let's get that JSON Path sorted out for you! Your original path has a few syntax and structure issues—let's break it down and fix it step by step.

First, let's make sure we're working with valid JSON (your snippet was missing the outer object wrapper and had a trailing comma, so here's the cleaned-up version):

{
  "Vehicle": {
    "code": "BCA",
    "name": "COLL",
    "description": "Collision",
    "limitTerms": [],
    "deductibleTerms": [
      {
        "code": "qsw",
        "name": "",
        "value": "500",
        "valueCode": "",
        "valueDescription": ""
      }
    ],
    "otherTerms": []
  }
}

What Was Wrong With Your Original Path?

Your path $.vehicle[description='Collision' and .deductibleTerms[*].value] had three key issues:

  • Case sensitivity: JSON Path is case-sensitive—your root node is Vehicle, not vehicle.
  • Incorrect conditional syntax: You need to filter the Vehicle node first using its description property, then traverse to deductibleTerms.
  • Misplaced traversal: The deductibleTerms[*].value part shouldn't be inside the filter condition for the Vehicle node.

Correct JSON Paths

Here are the working paths to extract the "500" value, using either description or name to locate the right Vehicle node:

1. Using description="Collision" to Locate the Node

$.Vehicle[?(@.description == 'Collision')].deductibleTerms[*].value
  • $.Vehicle: Targets the root-level Vehicle object.
  • [?(@.description == 'Collision')]: Filters to only keep the Vehicle where the description matches "Collision".
  • .deductibleTerms[*]: Iterates over all items in the deductibleTerms array.
  • .value: Extracts the value field from each array item.

2. Using name="COLL" to Locate the Node

If you prefer to use the name field instead, just swap the filter condition:

$.Vehicle[?(@.name == 'COLL')].deductibleTerms[*].value

3. Simplified Version (For Fixed Structures)

If you know there's only one Vehicle node and it will always have the deductibleTerms array with the value you need, you can skip the filter entirely for a more concise path:

$.Vehicle.deductibleTerms[0].value

This directly grabs the value from the first (and only) item in the deductibleTerms array.

These paths work in most popular JSON Path implementations (like Jayway JsonPath, jsonpath-ng, etc.).

内容的提问来源于stack exchange,提问作者Umair

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:47:51