0

I have a data file in JSON format. The following is a sample:

{"ts":"2018-01-04T02:19:05.144-06:00","ct":"{\"Antenna\":3,\"OlioId\":1,\"TagId\":\"30742C40A426936D4B681B3E\",\"TimeStamp\":\"2018-01-04T02:19:05.144-06:00\"}"}
{"ts":"2018-01-04T02:19:05.167-06:00","ct":"{\"Antenna\":3,\"OlioId\":1,\"TagId\":\"307405B6E8538FED4B68F19F\",\"TimeStamp\":\"2018-01-04T02:19:05.167-06:00\"}"}
{"ts":"2018-01-04T02:19:05.214-06:00","ct":"{\"Antenna\":4,\"OlioId\":1,\"TagId\":\"30742C40A426936D4B691D5D\",\"TimeStamp\":\"2018-01-04T02:19:05.214-06:00\"}"}
{"ts":"2018-01-04T02:19:05.448-06:00","ct":"{\"Antenna\":6,\"OlioId\":1,\"TagId\":\"30742C40A42692ED4B67CD2E\",\"TimeStamp\":\"2018-01-04T02:19:05.448-06:00\"}"}

Using the rjson library I tried creating a dataframe but I can't get it to work out. I'm ending up with a list of two items ts and ct.

What I'd like to do is create a dataframe of the ct item with variable names Antenna, OlioId, TagID, and TimeStamp.

Can anyone give me their recommendations on how to do this?

Bentaye
  • 9,403
  • 5
  • 32
  • 45
ds_guy
  • 143
  • 2
  • 5
  • 2
    When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. Show the code you tried. Your objects only really have two columns, `ts` and `ct`. The `ct` value is a string that happens to look like json but it's not json. How did you get such an object in the first place? Looks like something went wrong earlier in the process. – MrFlick Mar 02 '18 at 22:12
  • You have newline delimited JSON. Use `ndjson::stream_in()` or `jsonlite::stream_in()` from the original file. Otherwise use `ndjson::flatten()` from an already read-in character vector. – hrbrmstr Mar 03 '18 at 00:51
  • hrbrmstr: Thank you. ndjson is just what I was looking for. – ds_guy Mar 05 '18 at 15:53

0 Answers0