title: Dart FormatException: Unexpected character (at character 1) in empty json
body: <p>Basically what the title says, simply trying to implement a condition that either writes to a an existing file or decodes the json and then writes to the same file.
  code:</p>
  <pre><code>import 'dart:io';
  import 'dart:convert';
  import 'ToDo.dart';
  
  void main() async{
      print(&quot;hello&quot;);
      int prio1;
      print(&quot;Title:&quot;);
       String? title1 = stdin.readLineSync();
      print(&quot;description:&quot;);
       String? des = stdin.readLineSync();
  
      ToDo test = new ToDo(title1, des, 0, false);
      String  test11 = jsonEncode(test);
  
      print(test11);
      final filename = 'vault.json';
      if(File(filename).length == 0)
      {
        new File(filename).writeAsString(&quot;[&quot;+test11+&quot;]&quot;);
      }
      else{
        String test = await jsonDecode(filename);
        String test2 = test.substring(0, test.length - 1);
        String test3 = &quot;,&quot;+test2 +&quot;]&quot;;
        new File(filename).writeAsString(test3);
      }
  
  }
  </code></pre>
  <p>my json file &quot;vault.json&quot; is empty, yet I get this error:</p>
  <pre><code>Unhandled exception:
  FormatException: Unexpected character (at character 1)
  vault.json
  ^
  
  #0      _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1405:5)
  #1      _ChunkedJsonParser.parseNumber (dart:convert-patch/convert_patch.dart:1272:9)
  #2      _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:937:22)
  #3      _parseJson (dart:convert-patch/convert_patch.dart:40:10)
  #4      JsonDecoder.convert (dart:convert/json.dart:612:36)
  #5      JsonCodec.decode (dart:convert/json.dart:216:41)
  #6      jsonDecode (dart:convert/json.dart:155:10)
  #7      main (file:///D:/Code/dart/json/json.dart:23:27)
  #8      _delayEntrypointInvocation.&lt;anonymous closure&gt; (dart:isolate-patch/isolate_patch.dart:297:19)
  #9      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
  </code></pre>
  <p>any help appreciated!</p>
  <p>edit:added ToDo.dart in case you want to run the program</p>
  <pre><code>class ToDo {
      String? title,description;
      int prio;
      bool completed;
  
      ToDo(this.title, this.description, this.prio, this.completed);
  
      ToDo.fromJson(Map&lt;String,dynamic&gt; json):
          title = json['title'],
          description = json['description'],
          prio = json['prio'],
          completed = json['completed'];
  
      Map&lt;String,dynamic&gt; toJson() =&gt; {
          'title':title,
          'description':description,
          'prio':prio,
          'completed':completed,
      };
  
  }
  </code></pre>