0

I am putting data into a json file with Jsonserializer with the indent option turned on, but the arrays I'm storing aren't formatted to my liking.

[
  {
    "filePath": "C:\\Users\\Audio\\2.mp3",
    "playAddress": 0,
    "loop": false,
    "SpeakerVolumes": [
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0,
      0
    ],

this is a snippet of what part of the json file looks like.

void saveCfg()
        {
            Console.WriteLine(firstSave);
            if (firstSave == true)
            {
                firstSave = false;
                SaveFileDialog saveFileDialog1 = new SaveFileDialog();

                saveFileDialog1.Filter = "config files (*.json)|*.json|All files (*.*)|*.*";
                saveFileDialog1.FilterIndex = 2;
                saveFileDialog1.RestoreDirectory = true;

                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    writeFilePath = saveFileDialog1.FileName;
                }
            }
            List<AudioDataFormat> audioData = new List<AudioDataFormat>();
            //Console.WriteLine()
            for (int i = 0; i < audioFilePaths.Count; i++)
            {
                audioData.Add(new AudioDataFormat()
                {
                    filePath = audioFilePaths[i],
                    playAddress = playAddress[i],
                    loop = loop[i],
                    SpeakerVolumes = speakerVolumes[i],
                    fades = fades[i],
                    fadeAddress = fadeAddress[i],
                    fadeVol = fadeVol[i],
                    fadeTime = fadeTime[i],
                });
            }
            var options = new JsonSerializerOptions { WriteIndented = true };
            string json = JsonSerializer.Serialize(audioData.ToArray(), options);
            File.WriteAllText(writeFilePath, json);
        }

this is how i save the data in the json file.

I would like the entire array to be in one line. Is this possible?

Kind regards Guus

Gvmarle
  • 11
  • 1
  • 1
    can you provide a full code sample? – Jonathan Alfaro Aug 18 '22 at 08:25
  • 2
    It's either all or nothing, so write your own JsonConverter, see [duplicate](https://stackoverflow.com/questions/58395416/write-listdouble-to-json-array-without-indentation-using-system-text-json). – CodeCaster Aug 18 '22 at 08:34

0 Answers0