Skip to contents

This is a list of integer values used for setting flags on the yyjson code directly. This is an ADVANCED option and should be used with caution.

Usage

yyjson_read_flag

Format

An object of class list of length 16.

Details

Some of these settings overlap and conflict with code needed to handle the translation of JSON values to R.

opts_read_json(yyjson_read_flag = c(yyjson_read_flag$x, yyjson_read_flag$y, ...))

YYJSON_READ_NOFLAG

Default option (RFC 8259 compliant):

  • Read positive integer as uint64_t.

  • Read negative integer as int64_t.

  • Read floating-point number as double with round-to-nearest mode.

  • Read integer which cannot fit in uint64_t or int64_t as double.

  • Report error if double number is infinity.

  • Report error if string contains invalid UTF-8 character or BOM.

  • Report error on trailing commas, comments, inf and nan literals.

YYJSON_READ_INSITU

Read the input data in-situ. This option allows the reader to modify and use input data to store string values, which can increase reading speed slightly. The caller should hold the input data before free the document. The input data must be padded by at least YYJSON_PADDING_SIZE bytes. For example: "[1,2]" should be "[1,2]\0\0\0\0", input length should be 5.

YYJSON_READ_STOP_WHEN_DONE

Stop when done instead of issuing an error if there's additional content after a JSON document. This option may be used to parse small pieces of JSON in larger data, such as "NDJSON"

YYJSON_READ_ALLOW_TRAILING_COMMAS

Allow single trailing comma at the end of an object or array, such as "[1,2,3,]"

YYJSON_READ_ALLOW_COMMENTS

Allow C-style single line and multiple line comments (non-standard).

YYJSON_READ_ALLOW_INF_AND_NAN

Allow inf/nan number and literal, case-insensitive, such as 1e999, NaN, inf, -Infinity (non-standard).

YYJSON_READ_NUMBER_AS_RAW

Read all numbers as raw strings (value with "YYJSON_TYPE_RAW" type), inf/nan literal is also read as raw with "ALLOW_INF_AND_NAN" flag.

YYJSON_READ_ALLOW_INVALID_UNICODE

Allow reading invalid unicode when parsing string values (non-standard). Invalid characters will be allowed to appear in the string values, but invalid escape sequences will still be reported as errors. This flag does not affect the performance of correctly encoded strings. WARNING: Strings in JSON values may contain incorrect encoding when this option is used, you need to handle these strings carefully to avoid security risks.

YYJSON_READ_BIGNUM_AS_RAW

Read big numbers as raw strings. These big numbers include integers that cannot be represented by "int64_t" and "uint64_t", and floating-point numbers that cannot be represented by finite "double". The flag will be overridden by "YYJSON_READ_NUMBER_AS_RAW" flag.

YYJSON_READ_ALLOW_BOM

Allow UTF-8 BOM and skip it before parsing if any (non-standard)

YYJSON_READ_ALLOW_EXT_NUMBER

Allow extended number formats (non-standard):

  • Hexadecimal numbers

  • Numbers with leading or trailing decimal point

  • Numbers with a leading plus sign

YYJSON_READ_ALLOW_EXT_ESCAPE

Allow extended escape sequences in strings (non-standard):

  • Additional escapes

  • Hex escapes

  • Line continuation: backslash followed by line terminator sequences.

  • Unknown escape: if backslash is followed by an unsupported character, the backslash will be removed and the character will be kept as-is.

YYJSON_READ_ALLOW_EXT_WHITESPACE

Allow extended whitespace characters (non-standard):

  • Vertical tab and form feed

  • Line separator and paragraph separator

  • Non-breaking space

  • Byte order mark

  • Other Unicode characters in the Zs (Separator, space) category

YYJSON_READ_ALLOW_SINGLE_QUOTED_STR

Allow strings enclosed in single quotes (non-standard)

YYJSON_READ_ALLOW_UNQUOTED_KEY

Allow object keys without quotes (non-standard), such as {a:1,b:2}`. This extends the ECMAScript IdentifierName rule by allowing any non-whitespace character with code point above U+007F.

YYJSON_READ_JSON5

Allow JSON5 format. This flag supports all JSON5 features with some additional extensions:

  • Accepts more escape sequences than JSON5.

  • Unquoted keys are not limited to ECMAScript IdentifierName.

  • - Allow case-insensitive NaN, Inf and Infinity literals.

Examples

read_json_str(
   '[12.3,] // a comment', 
   opts = opts_read_json(yyjson_read_flag = c(
      yyjson_read_flag$YYJSON_READ_ALLOW_TRAILING_COMMAS,
      yyjson_read_flag$YYJSON_READ_ALLOW_COMMENTS
   ))
 )
#> [1] 12.3