Description Usage Arguments Details See Also
These functions wrap jsonlite::fromJSON
and jsonlite::toJSON
and make it easier to work with JSON inside of a data set.
1 2 3 |
x |
An object to be converted to/from JSON. |
keep_na |
A single logical value indicating whether to return |
... |
Additional arguments to be passed to |
rm_class |
A single logical value indicating whether to remove the
|
A common use case is where all selected answers to a multi-select checkbox survey question are stored in a single column of a wide-formatted data set. JSON encoding is a simply way to ensure answer text doesn't interfere with the process of parsing the different answers (e.g. if there was a semi-colon in the answer and your separator was a semi-colon).
jsonlite
does not support the preservation of NA
values that
would be needed for this use case, such as when someone skipped the
multi-select question. jsonlite
throws an error reading an NA
value and writes NA
to a JSON object containing an NA
value,
instead of simply returning NA. To make the functions more friendly for data
sets, NA
values are returned as NA
during both reading and
writing.
When storing JSON in data frames, JSON objects will be stored as a character
vector and be stripped of their "json"
class that jsonlite
attaches. Losing the "json"
class does not have any detrimental
effects, but unneccessary warnings may be thrown if data frame functions
(e.g. dplyr::mutate
) have to remove the class for you. to_JSON
strips the "json"
class by default to prevent warning spam.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.