jsonenc: JSON Encode

View source: R/base.R

jsonencR Documentation

JSON Encode

Description

Minimal JSON encoder. Converts an R object to a JSON string.

Usage

jsonenc(x)

Arguments

x

An R object to encode as JSON.

Details

This is a minimal implementation designed for creating HTTP API request bodies.

Value

A character string containing the JSON representation.

Type Mappings

  • Named list -> object {}

  • Unnamed list -> array ⁠[]⁠

  • Character -> string (with escaping)

  • Numeric/integer -> number

  • Logical -> true/false

  • NULL, NA -> null

  • Scalars (length 1) -> primitive value

  • Vectors (length > 1) -> array ⁠[]⁠

  • Unsupported types (e.g., functions) -> null

See Also

jsondec()

Examples

jsonenc(list(name = "John", age = 30L))
jsonenc(list(valid = TRUE, count = NULL))
jsonenc(list(nested = list(a = 1, b = list(2, 3))))
jsonenc(list(nums = 1:3, strs = c("a", "b")))


secretbase documentation built on Feb. 5, 2026, 9:09 a.m.