Learn R Programming

mojson (version 0.1)

diffj: Multiple JSON Objects Diff

Description

Find the difference between multiple JSON objects yielded by create, delete and update operations.

Usage

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

Arguments

json_new

list. The new JSON objects.

json_old

list. The old JSON objects.

sep

character. A character/string used to separate keys in the nesting path. Defaults to @ to avoid the occasional overriding. Not recommended to use some risky characters like . and \. When compact = FALSE, it is unnecessary to assign sep explicitly, unless @ has been used in the keys.

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. Contains the difference result, including path create, path delete and value change results.

Details

This function finds out the difference between two JSON lists. And the difference is as follows:

  • create, stores the flattened result of objects only in the json_new, that is some JSON objects have been created.

  • delete, stores the flattened result of objects only in the json_old, that is some JSON objects have been deleted.

  • change, stores the value update information in the common objects, reflected by '+(add)', and '-(remove)' in the chng_type field.

The change_summary provides the general information of value change.

Examples

Run this code
# NOT RUN {
library(mojson)
j1 <- list(list(x = 1, y = 2, b = list(m = 1, n = 1)),
          list(x = 2, y = 2, b = list(m = 1, n = 1)))
j2 <- list(list(x = 2, y = 3, b = list(m = 1)),
          list(x = 3, y = 2, b = list(m = 1, n = 1)))
diffj(j1, j2, primary = 'x')
# }

Run the code above in your browser using DataLab