[Rd] Issues converting from JSON to R

From: Kynn Jones <kynnjo_at_gmail.com>
Date: Fri, 12 Jun 2009 18:34:10 -0400

When converting from JSON to R it seems logical that a JSON array would correspond to an "unnamed" R list, while a JSON object would correspond to a "named" R list. E.g.
JSON: [1, 3.1415927, "foo", false, null] => R: list(1, 3.1415927, "foo", FALSE, NA); and

JSON { "int": 1, "float": 3.1415927, "string": "foo", "logical": false, "null": null } => R: list(int=1, float=3.1415927, string="foo", logical=FALSE, null=NA)

But I see at least a couple of problems with this scheme. First, how would one distinguish between the R versions of an empty JSON array (i.e. [ ]), and an empty JSON object (i.e. { })?

Second, JSON allows the empty key in an object (e.g., this is a valid JSON object: { "": 123 }), but as far as I can tell, R does not allow the empty string as a name in a named list:

> list(""=123)

Error: attempt to use zero-length variable name

Any suggestions for dealing with these edge cases would be much appreciated!

TIA! kynn

        [[alternative HTML version deleted]]

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 12 Jun 2009 - 22:38:02 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 12 Jun 2009 - 23:35:37 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive