-1

I have a multi-level JSON file like so:

{
  "key1":1,
  "key2":"a"
}

{
  "key1":2,
  "key2":"b"
}

My goal is to convert this file into a data frame with two columns and two rows like so:

ml_df
  key1 key2
1    1    a
2    2    b

At the moment, I have:

library(rjson)
ml_json <- fromJSON(file = "multi_level.json")
ml_df_fail <- as.data.frame(ml_json)

The problem is that ml_df_fail has only one row with two columns like so:

ml_df_fail
  key1 key2
1    1    a

How to read multi-level JSON files in R?

Joe
  • 1,628
  • 3
  • 25
  • 39

1 Answers1

1

How have you generated that JSON file?

Shouldn't it rather look something like:

[
  {
    "key1":1,
    "key2":"a"
  },

  {
    "key1":2,
    "key2":"b"
  }
]

For this, I can use jsonlite::fromJSON("test.json")

RolandASc
  • 3,863
  • 1
  • 11
  • 30