Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format a multi line string with triple quotes inside in JSON file?

Tags:

json

flutter

dart

I have markdown string to store in json file, so I am using multi line and so many things in the string. How can I store it in json object?

[
  { "title":  "Title of Ebook",
    "details": [
      {
        "head": "Introduction 1",
        "data": """It’s important to follow trends in your field to ensure you’re staying current on standards and protocols and perhaps more so in the field of coding. Programmers of all specialties can benefit from following 
#h this is a header
__italic__
industry-leading blogs to stay aware of the latest technologies.If you’re a coder of any sort you’ll want to subscribe to these useful programming blogs written by the top blogging coders.Each of these bloggers has made a name for themselves in the programming community by sharing relevant, high-quality information and tips for coders. They maintain their respective blogs well and keep current information posted on a regular basis.By following the best programming blogs you’ll find tips and shortcuts you may never have otherwise thought to try. Consider using an RSS feed reader through your phone or desktop browser to automatically download each new post from these top coding bloggers."""
      }
  }
]

When I will receive the string I will have the markdown style data from json.

like image 990
Md Abdul Halim Rafi Avatar asked Oct 27 '25 05:10

Md Abdul Halim Rafi


1 Answers

Your object is not closed correctly. There are closing brackets missing.

Not sure if it answers your question but you can do it like this:

import 'dart:convert';

main(List<String> arguments) {
  var json = [
    {
      "title": "Title of Ebook",
      "details": [
        {
          "head": "Introduction 1",
          "data":
              """It’s important to follow trends in your field to ensure you’re staying current on standards and protocols and perhaps more so in the field of coding. Programmers of all specialties can benefit from following 
#h this is a header
__italic__
industry-leading blogs to stay aware of the latest technologies.If you’re a coder of any sort you’ll want to subscribe to these useful programming blogs written by the top blogging coders.Each of these bloggers has made a name for themselves in the programming community by sharing relevant, high-quality information and tips for coders. They maintain their respective blogs well and keep current information posted on a regular basis.By following the best programming blogs you’ll find tips and shortcuts you may never have otherwise thought to try. Consider using an RSS feed reader through your phone or desktop browser to automatically download each new post from these top coding bloggers."""
        }
      ]
    }
  ];

  var encodedJson = jsonEncode(json);

  print(encodedJson);

  var details = json[0]['details'] as List;
  print(details[0]['data']);
}
like image 180
SebastianK Avatar answered Oct 28 '25 18:10

SebastianK



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!