ufodisko's avatar

Expected file to have JSONL format, where every line is a JSON dictionary

I'm trying to upload a JSONL file to an API endpoint, however, I keep getting this error.

[{"error":{"message":"Expected file to have JSONL format, where every line is a JSON dictionary. Line 1 is not a dictionary (HINT: line starts with: "{...").","type":"invalid_request_error","param":null,"code":null}},{"object":"list","data":[]}]

The file I'm selecting to upload has the extension jsonl and is properly formatted

{
  "name": "Gilbert", 
  "companies": [
    [
      "Microsoft"
    ], 
    [
      "Amazon"
    ]
  ]
}
{
  "name": "Alexa", 
  "companies": [
    [
      "Apple"
    ], 
    [
      "Google"
    ]
  ]
}

However, when the file gets uploaded to the storage directory, it is being converted to .json and returning the extension also says json

// Controller
Storage::putFile('avatars', $request->file('file'));
return $request->file('file')->extension();
// Vue
<form @submit.prevent="submit">
            <input type="file" @input="form.file= $event.target.files[0]" />
            <button type="submit">Submit</button>
</form>

export default defineComponent({
    setup() {
        const form = useForm({
            file: null,
        })

        function submit() {
            form.post('/upload')
        }

        return { form, submit }
    },
});
0 likes
2 replies
vincent15000's avatar

The file your are uploading has no reason to change its name.

Sure you have something in your code that renames your file. You have to find where and force to keep the initial name and extension.

Sinnbeck's avatar

Is that your api endpoint? If so, show the code for it.

1 like

Please or to participate in this conversation.