Learn R Programming

whapi (version 0.0.2)

whapi_log_pretty_json: Convert R objects to pretty JSON for logging

Description

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)

Value

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

Arguments

x

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

max

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

Examples

Run this code
whapi_log_pretty_json(list(a = 1, b = "test"))
whapi_log_pretty_json(mtcars[1:2, ], max = 100)

Run the code above in your browser using DataLab