json2html: JSON to HTML

View source: R/json2html.R

json2htmlR Documentation

JSON to HTML

Description

Render a formatted JSON string in HTML.

Usage

json2html(
  json,
  outfile = NULL,
  pandoc = FALSE,
  style = paste0("background-color: #051C55; color: #E76900; ",
    "font-size: 15px; font-weight: bold; margin: 0; ",
    "white-space: pre-wrap; outline: #051C55 solid 10px;"),
  keyColor = "crimson",
  numberColor = "chartreuse",
  stringColor = "lightcoral",
  trueColor = "#00cc00",
  falseColor = "#ff8080",
  nullColor = "cornflowerblue"
)

Arguments

json

a JSON string or a path to a JSON file

outfile

either a path to a html file, or NULL if you don't want to write the output to a file

pandoc

Boolean, whether to use pandoc

style

some CSS for the container, only if pandoc=FALSE

keyColor

color of the keys, only if pandoc=FALSE

numberColor

color of the numbers, only if pandoc=FALSE

stringColor

color of the strings, only if pandoc=FALSE

trueColor

color of the true keyword, only if pandoc=FALSE

falseColor

color of the false keyword, only if pandoc=FALSE

nullColor

color of the null keyword, only if pandoc=FALSE

Value

Nothing if outfile is not NULL, otherwise the HtML as a character string.

Examples

library(cppcheckR)
xml <- system.file("extdata", "order-schema.xml", package = "xml2")
json <- xml2json(xml)
html <- json2html(json)
library(htmltools)
if(interactive()){
  browsable(HTML(html))
}
# with pandoc
html <- json2html(json, pandoc = TRUE)
if(interactive()){
  browsable(HTML(html))
}

cppcheckR documentation built on June 10, 2022, 5:06 p.m.