Skip to content

Commit c24f596

Browse files
committed
timestamp recognizer
1 parent 3b699d0 commit c24f596

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

json_explorer/analyzer.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
from collections import Counter
2+
import dateparser
3+
4+
5+
def detect_timestamp(value):
6+
if not isinstance(value, str):
7+
return False
8+
parsed = dateparser.parse(value)
9+
return parsed is not None
210

311

412
def analyze_json(data):
@@ -47,7 +55,13 @@ def analyze_node(node):
4755

4856
return {"type": "list", "child_type": "mixed"}
4957
else:
50-
return {"type": type(node).__name__}
58+
if isinstance(node, str):
59+
if detect_timestamp(node):
60+
return {"type": "timestamp"}
61+
else:
62+
return {"type": "str"}
63+
else:
64+
return {"type": type(node).__name__}
5165

5266
def merge_object_summaries(summaries):
5367
key_structures = {}
@@ -173,6 +187,7 @@ def merge_list_summaries(summaries):
173187
"settings": {"theme": "dark", "notifications": True},
174188
},
175189
"tags": ["admin", "user"],
190+
"last_login": "2024-07-15T12:30:00Z",
176191
},
177192
{
178193
"id": 2,
@@ -187,6 +202,7 @@ def merge_list_summaries(summaries):
187202
},
188203
"tags": ["user"],
189204
"email": "[email protected]",
205+
"last_login": "not a date",
190206
},
191207
],
192208
"metadata": {"total": 2, "created": "2024-01-01"},

0 commit comments

Comments
 (0)