This function serializes R data to JSON format using a specified structure. The main purpose is to provide a type-safe way to convert R objects into JSON strings that conform to a predefined structure.
Since R is an array language, many typical serialization tasks can make interoperability with other languages difficult. It is not uncommon for an API to expect a scalar value, but R will serialize it as a length-1 vector.
This function is designed to handle such cases by providing a structure
that defines the expected types and formats of the data. The structure is
defined using the build_structure
function, which allows you to specify
the types of each field in the data. The function will then serialize the
data according to this structure, ensuring that the output is in the correct
format.