json_internal: Helper function for printing JSON objects

print_json_classR Documentation

Helper function for printing JSON objects

Description

This function powers the json_class and json_vec specific methods of the base generic base::print(). As it is applied recursively and recursion depth has to be controllable, the function is aware of both the current recursion depth (via cur_depth) and the maximally allowed recursion depth (via max_depth). Furthermore the printing style (colored output and UTF box characters for visualizing the tree structure) can be controlled through the layout argument. Under some circumstances, this requires a given node to know whether the parent node is a named object or not, which is passed from a parent node to its children through the unnamed_parent argument.

In order to enable fancy printing (colored output and UTF box characters for visualizing the tree structure), this function provides the required styling information. Fancy printing can be disabled by setting the fancy argument to FALSE, which yields ASCII characters for the tree structure and disables color. This was more or less directly copied from Hadley's lobstr package.

Usage

print_json_class(x, unnamed_parent = FALSE, cur_depth, max_depth,
  layout = style())

style(fancy = TRUE)

Arguments

x

The JSON object to print.

unnamed_parent

Whether the parent node is named or not (in some cases, a different box character has to be used if this is true).

cur_depth

The current recursion depth.

max_depth

The maximum recursion depth.

layout

Characters for printing the tree structure and styles to be applied to the different entities.

fancy

Logical switch to enable font styles, colors and UTF box characters.


nbenn/infx documentation built on May 20, 2022, 7:44 a.m.