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

JSONata数组上下文通配符*的行为文档位置咨询

Understanding JSONata's $.* Array Flattening Behavior

Great question! I’ve stumbled over this exact quirk with JSONata’s wildcard syntax before—its ability to flatten arrays feels almost hidden if you only look at the object-focused wildcard docs.

Let me break down where this behavior is documented and why it works:

  • First, remember that JSONata treats arrays as sequences under the hood. Unlike JSON arrays, JSONata sequences are inherently flat—they don’t support nesting. Any nested array in your input gets automatically expanded into the parent sequence when processed.
  • The $.* wildcard in an array context leverages this sequence behavior. When you use $.* on an array, it iterates over every element of the array, and since nested arrays are converted to flat sequences, the end result is a fully flattened set of values.

For example, if you run $.* against this input:

[1, [2, 3], [4, [5, 6]]]

You’ll get the flat sequence: 1, 2, 3, 4, 5, 6

Where to find this in the official docs

This behavior is covered in the "Sequences" section of the JSONata documentation. Specifically, the docs note that sequences are flat, and any operation that produces a sequence (like using a wildcard to iterate over array elements) will automatically flatten nested arrays into the top-level sequence.

While the wildcard (*) docs focus on object property access, the array flattening is a side effect of JSONata’s core sequence handling. You can also connect this to the "Descendant Wildcard (**)" section, which explicitly handles deep nesting, but $.* on an array is a simpler case of sequence expansion.

It’s definitely easy to miss since it’s not called out directly in the wildcard-specific docs, but once you grasp that JSONata prioritizes flat sequences over nested arrays, it makes perfect sense why $.* acts like an array flattener.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 07:14:48