SD card loads correctly, but won't load file

I have used an example project, and the file loads fine, but whenever I make the code, it stops working...

My code: (Not finished)

#include <SPI.h>
#include <SD.h>
#include <ArduinoJson.h>

const int inPin = 4;
const int outPin = 7;

File myFile;
JsonDocument doc;

void setup() {
  //Setup input and output pins
  pinMode(inPin, INPUT);
  pinMode(outPin, OUTPUT);
  Serial.begin(9600);
  while (!Serial) {
    ; // Wait for serial port to connect
  }
  Serial.print("Initializing SD card...");
  if (!SD.begin(2)) {
    Serial.println("Initialization failed");
    while (1);
  }
  Serial.println("Done");

  myFile = SD.open("index.json", FILE_WRITE);
  if (myFile) {
    Serial.print("File opened successfully");
    if (!myFile.available()) { //Check if file is empty or new 
    //Write default morse to index.json
    char defaultMorse[] = "{\"A\":\".-\",\"B\":\"-...\",\"C\":\"-.-.\",\"D\":\"-..\",\"E\":\".\",\"F\":\"..-.\",\"G\":\"--.\",\"H\":\"....\",\"I\":\"..\",\"J\":\".---\",\"K\":\"-...\",\"L\":\".-..\",\"M\":\"--\",\"N\":\"-.\",\"O\":\"---\",\"P\":\".--.\",\"Q\":\"--.-\",\"R\":\".-.\",\"S\":\"...\",\"T\":\"-\",\"U\":\"..-\",\"V\":\"...-\",\"W\":\".--\",\"X\":\"-..-\",\"Y\":\"-.--\",\"Z\":\"--..\"}";
    myFile.println(defaultMorse);
    myFile.close();
    } else {
      Serial.print("File is not empty!");
    }
  } else { 
    myFile.close();
    Serial.print("File failed to load");
    Serial.println(myFile);
    Serial.println(SD.open("index.json", FILE_WRITE));
  }
}

void loop() {
  //int inRead = digitalRead(inPin);
  //int outWrite = inRead; //Temporary for later code
  //digitalWrite(outPin, outWrite);
  //Serial.print(outWrite);
}

What does that mean, exactly? Please be detailed and specific.

And by the way, as far as I know, the SD library doesn't support long file names. It's 8.3 only.

I used the example project "Read Write" and it created and loaded the file successfully, but when I used the code that I made, it didn't work.

If I said to you "it doesn't work" about something, would you be able to tell me anything useful without me providing details about exactly what happened, what didn't happen, and what you expected to happen?

No. And neither can I.

Good luck with your project.

That's the thing. I don't have any other details other than "File failed to load".

SD library supports 8.3 filenames. The “.json” is the problem.

index.json

You can change to SdFat library. It supports long filenames.