Unable to use .JSONL file


I am working on the Answers endpoint. I was trying to create a file and then use to find answers. For that I saved a file for example,
{“text”: “Hello OpenAI”, “metadata”: “sample data”}
as demo.jsonl. Next, when I executed the code for the file id to generate,

import openai
openai.api_key = "YOUR-API-KEY"
response = openai.File.create(

I am getting error as openai.error.InvalidRequestError: Expected a JSONL file.

Not sure why this is happening. I dont know if simply saving a file as .jsonl in notepad++ is causing the file to be corrupted. I am not sure how to generate .jsonl file.

Not an OpenAI guy, but I have worked some with answers endpoint now.

Everything looks fine, I copied your example text, pasted it into notepad++, saved it with extension jsonl, copied your code above and ran it. Everything worked fine. Double check your jsonl file to make sure you didn’t get any other symbols in there by accident, it should work fine.

1 Like

Feel free to DM me the contents of your file. If I had to guess, those quotes might be some weird unicode character. Maybe try to retype them?

In general if you’re trying to create a jsonl file we recommend using your language’s json library.

Would it be possible for the error message to indicate something about what and where the problem is? I had a file that produced the error and yet when I copied all the contents and pasted it and saved it in another file all was fine. I checked that both cases it was UTF-8.

This error happens when your jsonl file cannot be parsed to a proper JSON structure.
I noticed the quotes you use are different from the regular quotes (") used in JSON, I suspect that might be your problem. You could try this example, using normal quotes:
{"text": "Hello OpenAI", "metadata": "sample data"}
The overall contents of your file seem fine (an object containing text and metadata).


Thanks everyone for your response. I gathered from the feedback that there must have been some quotes missing in the data that I entered since everything else seemed correct. So again I carefully entered the data in the file and executed it. Its working perfectly well now :slight_smile: and I am able to get answers from the file.


Yep! It’s on my todo list to make those errors a bit clearer, especially around json parsing issues