-1

I have a JSON file with time stamps that look like the following:

2012-03-01T00:05:55+00:00

I am not very familiar with JSON files and am looking for some thoughts on how to convert this to a more digestible format for analysis.

I am using pandas at the moment to upload the JSON so any rec's for python would be great!

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
madman
  • 153
  • 1
  • 4
  • 16

1 Answers1

2

Those are just ISO8601-formatted strings. JSON has no timestamp format. You can parse those into datetime objects, see How to parse an ISO 8601-formatted date?

The Pandas read_json() function handles that format natively, as long as you keep the convert_dates flag set to True or to a list of column names to treat as dates:

>>> import pandas as pd
>>> from io import StringIO
>>> sample = '{"0": {"event":true, "title": "Lorum Ipsum", "date": "2012-03-01T00:05:55+00:00"}}'
>>> pd.read_json(StringIO(sample), orient='index')
                 date  event        title
0 2012-03-01 00:05:55      1  Lorum Ipsum
>>> _.date
0   2012-03-01 00:05:55
Name: date, dtype: datetime64[ns]

The date column was automatically detected here because the column name indicated it was a date.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343