I am working with jsonlite package in R and want to convert a complex list to JSON object. assume that x is my list:
library(jsonlite)
x= list(a=1,B=2,c=list(D=4,e=5,'F g'='NAME',H=list(i=list(j=list(K=1)))))
x=
$a
[1] 1
$B
[1] 2
$c
$c$D
[1] 4
$c$e
[1] 5
$c$`F g`
[1] "NAME"
$c$H
$c$H$i
$c$H$i$j
$c$H$i$j$K
[1] 1
toJSON(x)
{"a":[1],"B":[2],"c":{"D":[4],"e":[5],"F g":["NAME"],"H":{"i":{"j":{"K":[1]}}}}}
how can I remove any special case in the JSON keys (like space between F and g as well as lower casing all keys?
I know one option is to operate on the list before feeding into the toJSON() function but even in that case, I have no ideas of how to rename all elements of a list (in particular my list contains some data.frames as well). Is there any regular expression method to do it?