I would like to convert an xts object which has the class Date
into JSON with jsonlite::toJSON
but it returns an error saying No method asJSON S3 class: zoo
.
My objective is to have a JSON file that can be handled by highcharts.js library, so I'm trying to have severals arrays [unixtime, value]
, something like this :
[[1489363200, -0.01766174], [1489968000, 0.00000021], [1490572800, 0.00000098]]
This is my xts object :
> obj
values
2017-03-13 -0.01766174
2017-03-20 0.00000021
2017-03-27 0.00000098
The documentation of toJSON
mention a Date
option that is used
to encode Date objects: must be one of 'ISO8601' or 'epoch', but for some reason there is the same error.
> data <- toJSON(obj, dataframe = "values", Date="epoch")
Error: No method asJSON S3 class: zoo
If I convert the xts into a dataframe or a matrix I can export in JSON but the format is no appropriate for highcharts.js :
[-0.0177,"2017-03-13"],[0,"2017-03-20"],[0,"2017-03-27"]]
Is there a possibility to export an xts object in a JSON by keeping the time serie ?
Thank you,