title: Unhandled Exception: FormatException: Unexpected character (at character 722)
body: <p>I'm saving an object as JSON and while trying to read it I get the error in the title.
  Is there a function in dart to properly format json data?</p>
  <p>Here's the full stack trace</p>
  <pre><code>[VERBOSE-2:ui_dart_state.cc(198)] Unhandled Exception: FormatException: Unexpected character (at character 722)
  ...1.25,&quot;tesco&quot;:0.95}},&quot;ticked&quot;:false}]{&quot;ID&quot;:2,&quot;product&quot;:{&quot;user&quot;:&quot;674971a44...
                                         ^
  #0      _ChunkedJsonParser.fail (dart:convert-patch/convert_patch.dart:1383:5)
  #1      _ChunkedJsonParser.parse (dart:convert-patch/convert_patch.dart:848:48)
  #2      _parseJson (dart:convert-patch/convert_patch.dart:35:10)
  #3      JsonDecoder.convert (dart:convert/json.dart:612:36)
  #4      JsonCodec.decode (dart:convert/json.dart:216:41)
  #5      jsonDecode (dart:convert/json.dart:155:10)
  #6      ShoppingListHandler.readShoppingListProducts (package:app/src/handlers/shopping_list_handler.dart:60:19)
  &lt;asynchronous suspension&gt;
  </code></pre>
  <p>and here's the json handler class</p>
  <pre class="lang-dart prettyprint-override"><code>class ShoppingListHandler {
  
    ShoppingListHandler._privateConstructor();
  
    static final ShoppingListHandler instance = ShoppingListHandler._privateConstructor();
  
    static File? _file;
  
    static const _fileName = 'shopping_list_file.txt';
  
    // Get the data file
    Future&lt;File&gt; get file async {
      if (_file != null) return _file!;
  
      _file = await _initFile();
      return _file!;
    }
  
    // Initialize file
    Future&lt;File&gt; _initFile() async {
      final _directory = await getApplicationDocumentsDirectory();
      final _path = _directory.path;
  
      // Check if file exists
      File file = File('$_path/$_fileName');
      if(await file.exists() == false){
        await file.create(recursive: true);
      }
  
      return file;
    }
  
    // Users
  
    static Set&lt;ShoppingListProduct&gt; _shoppingListSet = {};
  
    Future&lt;void&gt; writeShoppingList(ShoppingListProduct shoppingListProduct) async {
      final File fl = await file;
      _shoppingListSet.add(shoppingListProduct);
  
      // Now convert the set to a list as the jsonEncoder cannot encode
      // a set but a list.
      final _shoppingListMap = _shoppingListSet.map((e) =&gt; e.toJson()).toList();
  
      await fl.writeAsString(jsonEncode(_shoppingListMap));
    }
  
    Future&lt;List&lt;ShoppingListProduct&gt;&gt; readShoppingListProducts() async {
      final File fl = await file;
      final _content = await fl.readAsString();
  
      List&lt;dynamic&gt; _jsonData = [];
      if(_content.isNotEmpty){
        _jsonData = jsonDecode(_content);
      }
  
      final List&lt;ShoppingListProduct&gt; _shoppingListProducts = _jsonData
          .map(
            (e) =&gt; ShoppingListProduct.fromJson(e as Map&lt;String, dynamic&gt;),
      )
          .toList();
  
      return _shoppingListProducts;
    }
  
    Future&lt;void&gt; deleteShoppingListProduct(ShoppingListProduct shoppingListProduct) async {
      final File fl = await file;
  
      _shoppingListSet.removeWhere((e) =&gt; e == shoppingListProduct);
      final _shoppingListMap = _shoppingListSet.map((e) =&gt; e.toJson()).toList();
  
      await fl.writeAsString(jsonEncode(_shoppingListMap));
    }
  
    Future&lt;void&gt; updateShoppingListProduct({
      required int key,
      required ShoppingListProduct updatedShoppingListProduct,
    }) async {
      _shoppingListSet.removeWhere((e) =&gt; e.ID == updatedShoppingListProduct.ID);
      await writeShoppingList(updatedShoppingListProduct);
    }
  
  }
  </code></pre>
  <p>I take all the objects and put them into json data. Then I can read them and then cast it into a shoppingListProduct object.
  Any help will be much appreciated, thank you!</p>
  <p>Here's the shoppinglistproduct.txt</p>
  <pre><code>[{&quot;ID&quot;:0,&quot;product&quot;:{&quot;user&quot;:&quot;674971a44a04ad4fcefe0fdc77d23f63&quot;,&quot;id&quot;:0,&quot;name&quot;:&quot;Pepsi Max Cola Bottle&quot;,&quot;image&quot;:&quot;&quot;,&quot;brandName&quot;:&quot;Pepsi&quot;,&quot;productPrices&quot;:{&quot;asda&quot;:1.0,&quot;js&quot;:1.25,&quot;tesco&quot;:0.95}},&quot;ticked&quot;:false},{&quot;ID&quot;:1,&quot;product&quot;:{&quot;user&quot;:&quot;674971a44a04ad4fcefe0fdc77d23f63&quot;,&quot;id&quot;:1,&quot;name&quot;:&quot;Walkers Wotsits Giants Cheese Snacks 130G&quot;,&quot;image&quot;:&quot;&quot;,&quot;brandName&quot;:&quot;Walkers&quot;,&quot;productPrices&quot;:{&quot;asda&quot;:1.0,&quot;js&quot;:1.25,&quot;tesco&quot;:0.95}},&quot;ticked&quot;:false}]{&quot;ID&quot;:2,&quot;product&quot;:{&quot;user&quot;:&quot;674971a44a04ad4fcefe0fdc77d23f63&quot;,&quot;id&quot;:2,&quot;name&quot;:&quot;Rowntrees Fruit Pastilles Lollies 4X65ml&quot;,&quot;image&quot;:&quot;&quot;,&quot;brandName&quot;:&quot;Rowntree's&quot;,&quot;productPrices&quot;:{&quot;asda&quot;:1.0,&quot;js&quot;:1.25,&quot;tesco&quot;:0.95}},&quot;ticked&quot;:false}]
  </code></pre>