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

无需Schema,实现类GraphQL的JS对象子树提取,求推荐工具库

无需Schema的Node.js API字段子集查询工具推荐

我有一个Node.js API服务器,会返回大型JSON对象,希望给用户提供类似GraphQL的字段子集查询能力,但不需要定义Schema。这个API返回的对象既有标准字段,还允许用户在custom属性中添加任意自定义字段——GraphQL需要预定义查询字段描述符的方式并不适用于我的场景,因为custom字段可以是任意内容。

我期望用户能通过GET请求的查询参数,指定需要包含或排除的字段,具体需求示例如下:

原始返回对象

{
  "user": {
    "age": 25,
    "weight": 170,
    "name": "Joe"
  },
  "book": {
    "title": "Dune",
    "description": "Space opera",
    "location": {
      "planet": "Arakis",
      "population": 100000
    },
    "heroes": [
      {
        "name": "Duke",
        "age": 43
      },
      {
        "name": "Paul",
        "age": 16
      }
    ]
  }
}

具体查询场景

  • 精准获取指定字段:如果只想获取user.name和book.location.planet,对应的查询参数格式为:
    {'user.name': true, 'book.location.planet': true}
    
  • 包含整体对象但排除特定字段:如果想获取book下的所有字段但排除heroes,对应的查询参数格式为:
    {'book': true, 'book.heroes': false}
    
  • 数组元素查询:理想情况下工具需要支持数组的灵活查询,例如:
    {'book.heroes[0]': true} // 提取第一个元素
    {'book.heroes[:last].name': true} // 提取最后一个元素的name字段
    {'book.heroes.name': true} // 提取所有元素的name字段
    

请问有没有符合这类需求的工具库?


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 18:25:18