Convert buffered JSON objects To R

Share:

Description

Convert a collection of JSON objects into R objects.

Usage

1
newJSONParser(method = "R")

Arguments

method

use the C implementation, or the slower original R implementation

Value

A list of functions used for parsing objects

See Also

toJSON

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
sample_json <- '
	{
		"breakfast" : [ "milk", "fruit loops", "juice" ],
		"lunch" : [ "left over sushi" ]
	}
'

parser <- newJSONParser()

parser$addData( sample_json )
food <- parser$getObject()
print( food )

#This is equivalent to using FromJSON( sample_json )
#However, sample_json can be split into several parts:

### EXAMPLE 2:

part_1 <- '{ "breakfast" : [ "milk", "fruit loops", "juice" ], '
part_2 <- '"lunch" : [ "left over sushi" ]'
# close off the first object, and create a 2nd JSON object, which is simply an 
# array
part_3 <- '} [1,2,3,4,5]' 

parser <- newJSONParser()
parser$addData( part_1 )
parser$getObject() #returns NULL - since part_1 isn't complete
parser$addData( part_2 )
parser$getObject() #returns NULL - since part_2 still isn't complete
parser$addData( part_3 )
parser$getObject() #returns the first food object
parser$getObject() #returns the second array

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.