JSON 对象#

group JSON Path

函数

std::unique_ptr<cudf::column> get_json_object(cudf::strings_column_view const &col, cudf::string_scalar const &json_path, get_json_object_options options = get_json_object_options{}, rmm::cuda_stream_view stream = cudf::get_default_stream(), rmm::device_async_resource_ref mr = cudf::get_current_device_resource_ref())#

对输入字符串列中的所有行应用 JSONPath 字符串。

对输入的字符串列应用 JSONPath 字符串,其中列中的每一行都是有效的 json 字符串。输出按行以字符串列的形式返回。

https://tools.ietf.org/id/draft-goessner-dispatch-jsonpath-00.html 仅实现以下运算符:$ . [] *

抛出:

std::invalid_argument – 如果提供了无效的运算符或空名称

参数:
  • col – 输入字符串列。每行必须包含有效的 json 字符串

  • json_path – 要应用于每一行的 JSONPath 字符串

  • options – 用于控制函数行为的选项

  • stream – 用于设备内存操作和内核启动的 CUDA 流

  • mr – 用于分配设备内存的资源

返回:

包含检索到的 json 对象字符串的新字符串列

class get_json_object_options#
#include <json.hpp>

get_json_object() 的设置。

公有函数

explicit get_json_object_options() = default#

默认构造函数。

inline bool get_allow_single_quotes() const#

返回 true/false,取决于是否允许使用单引号表示字符串。

返回:

如果允许使用单引号,则为 true,否则为 false。

inline bool get_strip_quotes_from_single_strings() const#

返回 true/false,取决于单独返回的字符串值是否去除引号。

当设置为 true 时,如果给定行的返回值是单个字符串(不是对象或字符串数组),则去除字符串的引号,仅返回字符串本身的内容。示例

With strip_quotes_from_single_strings OFF:
Input  = {"a" : "b"}
Query  = $.a
Output = "b"

With strip_quotes_from_single_strings ON:
Input  = {"a" : "b"}
Query  = $.a
Output = b
返回:

如果单独返回的字符串值去除引号,则为 true。

inline bool get_missing_fields_as_nulls() const#

对象不包含的字段是否解释为 null。

当设置为 true 时,如果查询对象中不包含的字段,则返回 null。

With missing_fields_as_nulls OFF:
Input  = {"a" : [{"x": "1", "y": "2"}, {"x": "3"}]}
Query  = $.a[*].y
Output = ["2"]

With missing_fields_as_nulls ON:
Input  = {"a" : [{"x": "1", "y": "2"}, {"x": "3"}]}
Query  = $.a[*].y
Output = ["2", null]
返回:

如果缺失字段解释为 null,则为 true。

inline void set_allow_single_quotes(bool _allow_single_quotes)#

设置是否允许使用单引号表示字符串。

参数:

_allow_single_quotes – 表示期望行为的布尔值。

inline void set_strip_quotes_from_single_strings(bool _strip_quotes_from_single_strings)#

设置单独返回的字符串值是否去除引号。

参数:

_strip_quotes_from_single_strings – 表示期望行为的布尔值。

inline void set_missing_fields_as_nulls(bool _missing_fields_as_nulls)#

设置是否将缺失字段解释为 null。

参数:

_missing_fields_as_nulls – 表示期望行为的布尔值。