File uploading issue with json

It seems it doesn’t upload json file anymore.
I’ve always used this python method:

  def file_upload(self,
                 file_name: str
                 ) -> object:
    Upload a file to openai with given file_name

    file : object


    file = None
    with open(file_name,'rb') as f:      
        file = openai.files.create(
      except Exception as e:
    return file

But today it seems it accecpt only some json files.

ERROR 2024-01-02 10:38:42,182 Error code: 400 - {'error': {'message': "Invalid file format. Supported formats: ['c', 'cpp', 'csv', 'docx', 'html', 'java', 'json', 'md', 'pdf', 'php', 'pptx', 'py', 'rb', 'tex', 'txt', 'css', 'jpeg', 'jpg', 'js', 'gif', 'png', 'tar', 'ts', 'xlsx', 'xml', 'zip']", 'type': 'invalid_request_error', 'param': None, 'code': None}}

Same problem experienced on playground.


Happy New Year everyone!!

i think it depends on how is json file formatted.

With a json like this:


it doesn’t work.

With json like this:


It works…
but both are valid json files :roll_eyes:

I think there’s something weird with JSON file:

This JSON file is uploaded fine even if is malformed (the comma at the end):

  "40268" : {
    "id" : 3
  "40268" : {
    "id" : 4

This JSON doesn’t work even if formally is correct!!!

  "40268" : {
    "id" : 3
  "40268" : {
    "id" : 4

I really don’t understand what could be the problem :roll_eyes:

I’ve put a few hours into this, making different uploaders, validators, and rewriters, and here’s my ultimate conclusion:

This is accepted as a .json:

  '40268' : {
    'id' : 3,
  "40268" : {
    "id" : "test\nlines",
    "val" : +33,
    "3val" : .35,

Why? A JSON5 library doing the upload validating.

Summary of Features

The following ECMAScript 5.1 features, which are not supported in JSON, have been extended to JSON5.


  • Object keys may be an ECMAScript 5.1 IdentifierName.
  • Objects may have a single trailing comma.


  • Arrays may have a single trailing comma.


  • Strings may be single quoted.
  • Strings may span multiple lines by escaping new line characters.
  • Strings may include character escapes.

I’ve got a rewriter that will update the json if first refused, and it is taken in all cases above. But it is by regex. I’ll spend some more time later seeing if there’s a library feature that can do json->dict->json5 and force extra commas everywhere they can go.

The problem is that would get the file to code interpreter, but then you have a non “import json” file. Maybe just rename a txt?

1 Like

So it seems it’s JSON5, that’s ok. But anyway it doesn’t explain why “normal” json are refused. JSON5 is an extension of JSON, so it must be compliant with standard JSON file.
The strange thing is that if i upload a more structured json, with many other objects, it works :roll_eyes:
I really don’t understand.