Package 'json64'

Title: A 'Base64' Encode/Decode Package with Support for JSON Output/Input and UTF-8
Description: Encode/Decode 'base64', with support for JSON format, using two main functions: j_encode() and j_decode(). 'Base64' is a group of similar binary-to-text encoding schemes that represent binary data in an ASCII string format by translating it into a radix-64 representation, used when there is a need to encode binary data that needs to be stored and transferred over media that are designed to deal with textual data, ensuring that the data will remain intact and without modification during transport. <https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding> On the other side, JSON (JavaScript Object Notation) is a lightweight data-interchange format. Easy to read, write, parse and generate. It is based on a subset of the JavaScript Programming Language. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. JSON structure is built around name:value pairs and ordered list of values. <https://www.json.org> The first function, j_encode(), let you transform a data.frame or list to a 'base64' encoded JSON (or JSON string). The j_decode() function takes a 'base64' string (could be an encoded JSON) and transform it to a data.frame (or list, depending of the JSON structure). The package also contains a function, j_save(), to write data to a file using UTF-8 encoding.
Authors: Mauricio Santelices
Maintainer: Mauricio Santelices <[email protected]>
License: MIT + file LICENSE
Version: 0.2.1
Built: 2025-02-06 02:54:17 UTC
Source: https://github.com/msantelices/json64

Help Index


Decoding Function

Description

Used to decode a base64 string. By default the function expects an encoded json.

Usage

j_decode(str, json = TRUE)

Arguments

str

The string to be decoded.

json

Defaults to TRUE. If TRUE, the function expects str to be an encoded json and will return a data.frame or list, depending on JSON structure. If FALSE, the function will return an string.

Examples

# Decode an encoded string:

str <- "SGVsbG8gV29ybGQh"
j_decode(str, json = FALSE)

# Decode an encoded json:

encoded_json <- "W3sibXNnIjogIkhlbGxvIFdvcmxkISIsICJqc29uIjogdHJ1ZX1d"
j_decode(encoded_json)

Encoding Function

Description

Used to encode a data.frame or list. By default, the output will be a base64 encoded JSON.

Usage

j_encode(data, json = TRUE)

Arguments

data

A list or data.frame to encode.

json

Defaults to TRUE. If TRUE, the output will be a base64 encoded JSON, else, the output will be an encoded string.

Examples

# Transform a data.frame to an encoded JSON string
df <- iris
encoded <- j_encode(df, json = TRUE)

Save file Function

Description

Used to save data to a file in the working directory using UTF-8 encoding.

Usage

j_save(data, filename)

Arguments

data

The data to be saved

filename

A character string representing the name of the file.

Examples

# Write a JSON string to a UTF-8 encoded file

data <- "[{msg: 'Hello R users!', type: 'example'}]"
j_save(data, 'data.json')