Recent searches


No recent searches

JSON export file not matching documentation, unable to fix



Posted Dec 29, 2024

We're trying to parse the Zendesk JSON ticket export file that we downloaded from the admin center.  The documentation article Why is my full JSON export not a valid JSON?, says the following:

“While the file is not a valid JSON, each line within the file is valid JSON…”

 

And later says…

 

“Copy and paste the result into a JSON Validator, such as jsonlint.com, to see the format of the data.”

 

Also, the export documentation says that the JSON export file has each line starting with…

“{"ticket":{"id":....}}”

 

…but we actually see…

 

“{"url":"https://xxxxxx.zendesk.com/api/v2/tickets/12345.json","id":12345,”

 

…which makes us think that something is wrong in the export file from our account.

 

Additionally, when using tools like jsonlint.com, for many lines of the NDJSON exported file, I'm getting errors.  For example, I'm getting an error…

Error: Parse error on line 1:
...26T15:34:48.000Z"}},{"id":41234567889,"
-----------------------^
Expecting 'STRING', got ‘{’

 

…which is happening nearby the first of the comment nodes.

 

We really need to be able to parse the JSON, but it looks like it's malformed…and we can't seem to find a standard pattern to fix it.  Any thoughts?


0

1

1 comment

Hello,

How to Fix and Parse It
Step 1: Convert NDJSON to Standard JSON
Since each line in the file is a valid JSON object, you can wrap the entire file into an array by:

Adding an opening [ at the top of the file.
Adding a closing ] at the bottom of the file.
Replacing every newline (\n) with a comma (,) except for the last line.
Example Python Script to Convert NDJSON:

python
Copy code
input_file = "export.ndjson"
output_file = "export.json"

with open(input_file, "r") as infile, open(output_file, "w") as outfile:
   outfile.write("[\n")
   lines = infile.readlines()
   for i, line in enumerate(lines):
       if i < len(lines) - 1:
           outfile.write(line.strip() + ",\n")
       else:
           outfile.write(line.strip() + "\n")
   outfile.write("]")
print(f"Converted NDJSON to JSON and saved as {output_file}")
Step 2: Validate and Clean Up JSON
After converting, validate the JSON file using a tool like JSONLint. If you encounter errors:

Check for Improper Escaping: Look for unescaped characters such as quotes ("), slashes (\), or other symbols in strings.
Malformed Entries: Investigate any incomplete or corrupted lines and manually fix them.
Step 3: Parse JSON Programmatically
Once converted, you can parse the JSON in any programming language. For Python:

python
Copy code
import json

with open("export.json", "r") as json_file:
   data = json.load(json_file)

# Access ticket data
for ticket in data:
   print(ticket)
Why the Difference in Expected Format?
The discrepancy between what the documentation mentions ({"ticket":{"id":....}}) and what you see ({"url":"https://xxxxxx.zendesk.com/api/v2/tickets/12345.json","id":12345,) could mean:

Zendesk recently updated their export format.
Specific configurations in your account are affecting the output.
If you suspect the format is truly incorrect, it may be worth reaching out to Zendesk Support with a sample of the file to confirm.

 

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post