Skip to content

Converts R objects to a JSON string for easier inspection in logs. Falls back to utils::str() output if jsonlite is not available or if JSON conversion fails. Long outputs are truncated with whapi_trunc.

Usage

whapi_log_pretty_json(x, max = 2000L)

Arguments

x

An R object (list, data frame, etc.).

max

Integer. Maximum number of characters to print (default: 2000).

Value

A character string containing JSON (pretty-printed if possible).

Examples

whapi_log_pretty_json(list(a = 1, b = "test"))
#> [1] "{\n  \"a\": 1,\n  \"b\": \"test\"\n}"
whapi_log_pretty_json(mtcars[1:2, ], max = 100)
#> [1] "[\n  {\n    \"mpg\": 21,\n    \"cyl\": 6,\n    \"disp\": 160,\n    \"hp\": 110,\n    \"drat\": 3.9,\n    \"wt\": 2.62,\n... (truncated)"