JSONata 查询

用查询表达式从结构化文档中筛选字段、节点或匹配结果。

输入: 文本结果: 文本

文本输入

运行后查看结果

案例

Jsonata: .ref here returns the entire internal array

输入

[
  { "ref": [ 1,2 ] },
  { "ref": [ 3,4 ] }
]

Expected answer

JSON
[1,2]
查询表达式
$[0].ref
Jsonata: $ at the start of an expression refers to the entire input document, subscripting it with 0 selects the first item

输入

[
  { "ref": [ 1,2 ] },
  { "ref": [ 3,4 ] }
]

Expected answer

JSON
{"ref":[1,2]}
查询表达式
$[0]
Jsonata: $.field_reference flattens the result into a single array

输入

[
  { "ref": [ 1,2 ] },
  { "ref": [ 3,4 ] }
]

Expected answer

JSON
[1,2,3,4]
查询表达式
$.ref
Jsonata: $base64decode

输入

{}

Expected answer

JSON
"Hello World!"
查询表达式
$base64decode("SGVsbG8gV29ybGQh")
Jsonata: $base64encode

输入

{}

Expected answer

JSON
"SGVsbG8gV29ybGQh"
查询表达式
$base64encode("Hello World!")
Jsonata: Addition

输入

{
  "Numbers": [1, 2.4, 3.5, 10, 20.9, 30]
}

Expected answer

JSON
3.4
查询表达式
Numbers[0] + Numbers[1]
Jsonata: and

输入

{
  "Numbers": [1, 2.4, 3.5, 10, 20.9, 30]
}

Expected answer

JSON
true
查询表达式
(Numbers[2] != 0) and (Numbers[5] != Numbers[1])
Jsonata: Applies the index to the array returned by Phone.number.

输入

{
  "FirstName": "Fred",
  "Surname": "Smith",
  "Age": 28,
  "Address": {
    "Street": "Hursley Park",
    "City": "Winchester",
    "Postcode": "SO21 2JN"
  },
  "Phone": [
    {
      "type": "home",
      "number": "0203 544 1234"
    },
    {
      "type": "office",
      "number": "01962 001234"
    },
    {
      "type": "office",
      "number": "01962 001235"
    },
    {
      "type": "mobile",
      "number": "077 7700 1234"
    }
  ],
  "Email": [
    {
      "type": "work",
      "address": ["fred.smith@my-work.com", "fsmith@my-work.com"]
    },
    {
      "type": "home",
      "address": ["freddy@my-social.com", "frederic.smith@very-serious.com"]
    }
  ],
  "Other": {
    "Over 18 ?": true,
    "Misc": null,
    "Alternative.Address": {
      "Street": "Brick Lane",
      "City": "London",
      "Postcode": "E1 6RF"
    }
  }
}

Expected answer

JSON
"0203 544 1234"
查询表达式
(Phone.number)[0]
Jsonata: Casts the operands to strings, if necessary

输入

{
  "FirstName": "Fred",
  "Surname": "Smith",
  "Age": 28,
  "Address": {
    "Street": "Hursley Park",
    "City": "Winchester",
    "Postcode": "SO21 2JN"
  },
  "Phone": [
    {
      "type": "home",
      "number": "0203 544 1234"
    },
    {
      "type": "office",
      "number": "01962 001234"
    },
    {
      "type": "office",
      "number": "01962 001235"
    },
    {
      "type": "mobile",
      "number": "077 7700 1234"
    }
  ],
  "Email": [
    {
      "type": "work",
      "address": ["fred.smith@my-work.com", "fsmith@my-work.com"]
    },
    {
      "type": "home",
      "address": ["freddy@my-social.com", "frederic.smith@very-serious.com"]
    }
  ],
  "Other": {
    "Over 18 ?": true,
    "Misc": null,
    "Alternative.Address": {
      "Street": "Brick Lane",
      "City": "London",
      "Postcode": "E1 6RF"
    }
  }
}

Expected answer

JSON
"50true"
查询表达式
5&0&true
Jsonata: Concatenate 'FirstName' followed by space followed by 'Surname'

输入

{
  "FirstName": "Fred",
  "Surname": "Smith",
  "Age": 28,
  "Address": {
    "Street": "Hursley Park",
    "City": "Winchester",
    "Postcode": "SO21 2JN"
  },
  "Phone": [
    {
      "type": "home",
      "number": "0203 544 1234"
    },
    {
      "type": "office",
      "number": "01962 001234"
    },
    {
      "type": "office",
      "number": "01962 001235"
    },
    {
      "type": "mobile",
      "number": "077 7700 1234"
    }
  ],
  "Email": [
    {
      "type": "work",
      "address": ["fred.smith@my-work.com", "fsmith@my-work.com"]
    },
    {
      "type": "home",
      "address": ["freddy@my-social.com", "frederic.smith@very-serious.com"]
    }
  ],
  "Other": {
    "Over 18 ?": true,
    "Misc": null,
    "Alternative.Address": {
      "Street": "Brick Lane",
      "City": "London",
      "Postcode": "E1 6RF"
    }
  }
}

Expected answer

JSON
"Fred Smith"
查询表达式
FirstName & ' ' & Surname

相关工具

提取

操作参考

查看原始技术文档 (English)