toJson: To JSON (generic)

Description Usage Arguments Path-like identifiers Author(s) References See Also Examples

Description

Retrieves value from a nested object structure based on a path-like input with the last ID component being the actual object name that contains the value.

Usage

1
toJson(input, strict = FALSE, ...)

Arguments

input

Signature argument. Object containing JSON input.

strict

logical. TRUE: FALSE:

Further

arguments passed along to subsequent functions. In particular: toJson.

Path-like identifiers

Values for id are expected to be of structure a/b/c/.../z, i.e. path-like identifiers using a slash as separator. The identifier is transformed to a$b$c$...$z and then in turn to a valid get or assign expression (i.e. a$b$c$...$z and a$b$c$...$z <- value). Of course, "atomic" paths (e.g. only a) are also valid.

Author(s)

Janko Thyson [email protected]

References

http://github.com/Rappster/nestr

See Also

toJson-env-method

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
## Not run: 

##------------------------------------------------------------------------------  
## Names //
##------------------------------------------------------------------------------

input <- new.env()
setNested("europe/germany/berlin", value = 1, where = input, gap = TRUE)
setNested("europe/germany/hamburg", value = 2, where = input)
setNested("europe/germany/munich", value = 3, where = input)
setNested("america/usa/wisconsin/madison", value = 1, where = input, gap = TRUE)
setNested("south.america", value = 1, where = input)

toJson(input = input)
res <- fromJson(toJson(input), where = new.env())
ls(res)

##------------------------------------------------------------------------------  
## No names //
##------------------------------------------------------------------------------

input <- new.env()
setNested("[1]/id", value = 1, where = input, gap = TRUE)
setNested("[1]/name", value = "abc", where = input, gap = TRUE)
setNested("[2]/id", value = "2", where = input, gap = TRUE)
setNested("[2]/name", value = "def", where = input, gap = TRUE)
setNested("[2]/address", value = "asdfasdf", where = input, gap = TRUE)

toJson(input)
res <- fromJson(toJson(input), where = new.env())
ls(res)

##------------------------------------------------------------------------------  
## Mixed //
##------------------------------------------------------------------------------

input <- new.env()
setNested("[1]/id", value = 1, where = input, gap = TRUE)
setNested("[1]/name", value = "abc", where = input, gap = TRUE)
setNested("[2]/id", value = "2", where = input, gap = TRUE)
setNested("[2]/name", value = "def", where = input, gap = TRUE)
setNested("[2]/address", value = "asdfasdf", where = input, gap = TRUE)
setNested("john_doe/id", value = "2", where = input, gap = TRUE)
setNested("john_doe/name", value = "john doe", where = input, gap = TRUE)
setNested("john_doe/address", value = "asdfasdf", where = input, gap = TRUE)

toJson(input)
res <- fromJson(toJson(input), where = new.env())
ls(res)


## End(Not run)

rappster/nestr documentation built on May 24, 2017, 7:33 p.m.