diff options
| author | Kenneth Reitz <me@kennethreitz.com> | 2010-09-25 18:03:03 -0400 |
|---|---|---|
| committer | Kenneth Reitz <me@kennethreitz.com> | 2010-09-25 18:03:03 -0400 |
| commit | 3fc898e222c6215c46711d36677f70b8df33eca3 (patch) | |
| tree | 50a3395a186fc6d9e0f84e046a23b3362112b5fc /tablib/formats/_json.py | |
| parent | de46f45e2e13d0f689d895236c6bdcb0656593b2 (diff) | |
| download | tablib-3fc898e222c6215c46711d36677f70b8df33eca3.tar.gz | |
Auto-detectors operational.
Diffstat (limited to 'tablib/formats/_json.py')
| -rw-r--r-- | tablib/formats/_json.py | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/tablib/formats/_json.py b/tablib/formats/_json.py index 1f92b58..f7c88ee 100644 --- a/tablib/formats/_json.py +++ b/tablib/formats/_json.py @@ -36,3 +36,12 @@ def import_book(dbook, in_stream): data.title = sheet['title'] data.dict = sheet['data'] dbook.add_sheet(data) + + +def detect(stream): + """Returns True if given stream is valid JSON.""" + try: + json.loads(stream) + return True + except json.decoder.JSONDecodeError: + return False
\ No newline at end of file |
