Skip to content

Commit

Permalink
Merge pull request #2025 from geekscrapy/jsonl_slash_comments
Browse files Browse the repository at this point in the history
[jsonl] Allow slash comments
  • Loading branch information
anjakefala authored Sep 14, 2023
2 parents 8c89039 + cc327cc commit 8351bce
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions sample_data/test.jsonl
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@
{"key1": "2018-07-27 16:44", "key2": "bar", "amt": null}
{"key1": "2018-07-27 18:44", "key2": "baz", "amt": ".01", "qty": "256"}
{"key1": "2018-10-20 18:44", "key2": "foo", "amt": ".01", "qty": "30.0"}

# {"key1": "2018-10-20 18:44", "key2": "foo", "amt": ".01", "qty": "30.0"}
//{"key1": "2018-10-20 18:44", "key2": "foo", "amt": ".01", "qty": "30.0"}
5 changes: 3 additions & 2 deletions visidata/loaders/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,11 @@ class JsonSheet(InferColumnsSheet):
def iterload(self):
with self.source.open(encoding=self.options.encoding) as fp:
for L in fp:
L = L.strip()
try:
if L.startswith('#'): # skip commented lines
if not L: # skip blank lines
continue
elif not L.strip(): # skip blank lines
elif L.startswith(('#', '//')): # skip commented lines
continue
ret = json.loads(L, object_hook=AttrDict)
if isinstance(ret, list):
Expand Down

0 comments on commit 8351bce

Please sign in to comment.