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

如何编写JSONPath表达式筛选指定条件的文件子节点?

Solution for Targeting Valid .ord Files in JSONPath

Got it, let's refine your JSONPath expression to account for both file/directory distinctions and the specific extension you need. Here's the exact expression you should use:

$.children[?(@.isfile == true && @.extension == 'ord')].name

Breakdown of the Conditions:

  • @.isfile == true: This filters out any directory nodes (where isfile is false) and ensures we only look at actual file entries.
  • && @.extension == 'ord': This adds the original check for files with the .ord extension, combining the two requirements with a logical AND.

Extra Rigor: Ensuring the extension Property Exists

If you want to be extra safe (in case some file nodes don't have an extension property at all), you can add an exists() check to avoid unexpected matches:

$.children[?(@.isfile == true && exists(@.extension) && @.extension == 'ord')].name

This version will skip any file nodes that don't have an extension field entirely, even if isfile is true.

Example Test Case

Let's say you have this JSON structure:

{
  "children": [
    { "name": "report.ord", "isfile": true, "extension": "ord" },
    { "name": "data.csv", "isfile": true, "extension": "csv" },
    { "name": "docs", "isfile": false },
    { "name": "temp-file", "isfile": true }
  ]
}

Using either expression above will return only ["report.ord"]—exactly the result you want, ignoring directories, non-.ord files, and files missing the extension property.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.29 08:40:06