Learn R Programming

mojson (version 0.1)

alignj: JSON Lists Alignment

Description

Align the two JSON lists by specifying the primary path(keys), to support the left/inner/right-join style comparison.

Usage

alignj(json_new, json_old, sep = "@", primary)

Arguments

json_new

list. The new JSON list.

json_old

list. The old JSON list.

sep

character. A character/string passed to flattenj. Defaults to @ to avoid the occasional overriding. Not recommended to use some risky characters like . and \.

primary

character. The primary path(keys) for identifying a unique JSON object. The value provided should contain the sep value to specify the nesting information unless it is an outermost key.

Value

list. The result list contains the alignment information of three types: the primary paths only in the new JSON, only in the old JSON, and in both.

Details

The function borrows the idea from the data set operation, and the result contains:

  • new, contains the flattening result of json_new.

  • old, contains the flattening result of json_old.

  • common_primary, contains the primary paths both in json_new and json_old.

  • new_primary, contains the primary paths only in json_new.

  • old_primary, contains the primary paths only in json_old.

Examples

Run this code
# NOT RUN {
library(mojson)
j1 <- list(list(id = list(x = 1 ,y = 2), gender = 'M'),
           list(id = list(x = 2 ,y = 2), gender = 'M'))
j2 <- list(list(id = list(x = 2 ,y = 2), gender = 'F'),
           list(id = list(x = 3 ,y = 2), gender = 'F'))
alignj(j1, j2, primary = 'id@x')
# }

Run the code above in your browser using DataLab