2

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.

Md Abdul Halim Rafi
  • 1,810
  • 1
  • 17
  • 25

1 Answers1

5

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']);
}
SebastianK
  • 712
  • 4
  • 19
  • 1
    There is no need for triple quotation in your JSON file. If you decode the written JSON file, the corresponding strings will be equal. – SebastianK Nov 04 '19 at 15:51