j_data_type {rjsoncons}R Documentation

Detect JSON and NDJSON data and path types

Description

j_data_type() uses simple rules to determine whether 'data' is JSON, NDJSON, file, url, or R.

j_path_type() uses simple rules to identify whether path is a JSONpointer, JSONpath, or JMESpath expression.

Usage

j_data_type(data)

j_path_type(path)

Arguments

data

a character() JSON string or NDJSON records, or the name of a file or URL containing JSON or NDJSON, or an R object parsed to a JSON string using jsonlite::toJSON().

path

character(1) JSONpointer, JSONpath or JMESpath query string.

Details

j_data_type() without any arguments reports possible return values: "json", "ndjson", "file", "url", "R". When provided an argument, j_data_type() infers (but does not validate) the type of data based on the following rules:

j_path_type() without any argument reports possible values: "JSONpointer", "JSONpath", or "JMESpath". When provided an argument, j_path_type() infers the type of path using a simple but incomplete classification:

Because of these rules, the valid JSONpointer path "@" is interpreted as JMESpath; use jsonpointer() if JSONpointer behavior is required.

Examples

j_data_type()                            # available types
j_data_type("")                          # json
j_data_type('{"a": 1}')                  # json
j_data_type(c('[{"a": 1}', '{"a": 2}]')) # json
j_data_type(c('{"a": 1}', '{"a": 2}'))   # ndjson
j_data_type(list(a = 1, b = 2))          # R
fl <- system.file(package = "rjsoncons", "extdata", "example.json")
j_data_type(fl)                          # c('json', 'file')
j_data_type(readLines(fl))               # json

j_path_type()                            # available types
j_path_type("")                          # JSONpointer
j_path_type("/locations/0/name")         # JSONpointer
j_path_type("$.locations[0].name")       # JSONpath
j_path_type("locations[0].name")         # JMESpath


[Package rjsoncons version 1.3.1 Index]