Skip to content

Instantly share code, notes, and snippets.

@hargup
Created October 19, 2022 03:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hargup/017c83b24b2bb23a3986eb80349ca220 to your computer and use it in GitHub Desktop.
Save hargup/017c83b24b2bb23a3986eb80349ca220 to your computer and use it in GitHub Desktop.
Validate if a file a valid jsonl file
import fileinput
import json
def valid_json(json_str):
try:
json.loads(json_str)
return True
except:
return False
return True
for ln, line in enumerate(fileinput.input()):
if not valid_json(line):
print("Error in line %s" % str(ln+1))
print("line: %s" % line)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment