Learn R Programming

secretbase (version 1.2.0)

jsonenc: JSON Encode

Description

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

Usage

jsonenc(x)

Value

A character string containing the JSON representation.

Arguments

x

An R object to encode as JSON.

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

Details

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

See Also

jsondec()

Examples

Run this code
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")))

Run the code above in your browser using DataLab