0

I converted a excel file to a JSON object in R using jsonlite package.I want the whole array as a value to a key and add other some more key value pairs to that object.

The JSON array I got after converting the excel file looks like this -

[{
        "Sno": xxx,
        "Token": xxx,
        "Name": "xxx",
        "Location": "xxxx",
        "COE": "xxx",
        "Grade": "xxx",

    }, {
        "Sno": xxx,
        "Token": xxx,
        "Name": "xxxx",
        "Location": "xxxx",
        "COE": "xxxx",
        "Grade": "xxx",
    }, {

and so on..

The output i require is -:

    {
        "key1": "value1",
        "key2": "value2",
        "key3": "value3",
        "key4": [{
            "Sno": xxx,
            "Token": xxx,
            "Name": "xxx",
            "Location": "xxxx",
            "COE": "xxx",
            "Grade": "xxx",

        }, {
            "Sno": xxx,
            "Token": xxx,
            "Name": "xxxx",
            "Location": "xxxx",
            "COE": "xxxx",
            "Grade": "xxx",
        }, {

Please suggest how to do it or atleast point me in the right direction.

zx8754
  • 52,746
  • 12
  • 114
  • 209
Aakash
  • 79
  • 6

1 Answers1

1

Well I figured it out like this-

x<-list(key1="value1",key2="value2",key3="value3",key4=list(data_frame))
library(jsonlite)
final<-toJSON(x)
Aakash
  • 79
  • 6