Minimal JSON encoder. Converts an R object to a JSON string.
Type Mappings
Named list -> object
{}Unnamed list -> array
[]Character -> string (with escaping)
Numeric/integer -> number
Logical ->
true/falseNULL,NA->nullScalars (length 1) -> primitive value
Vectors (length > 1) -> array
[]Unsupported types (e.g., functions) ->
null
Examples
jsonenc(list(name = "John", age = 30L))
#> [1] "{\"name\":\"John\",\"age\":30}"
jsonenc(list(valid = TRUE, count = NULL))
#> [1] "{\"valid\":true,\"count\":null}"
jsonenc(list(nested = list(a = 1, b = list(2, 3))))
#> [1] "{\"nested\":{\"a\":1,\"b\":[2,3]}}"
jsonenc(list(nums = 1:3, strs = c("a", "b")))
#> [1] "{\"nums\":[1,2,3],\"strs\":[\"a\",\"b\"]}"