jsonStringWriter function

JsonWriter<String> jsonStringWriter(
  1. StringSink sink, {
  2. String? indent,
  3. bool asciiOnly = false,
})

Creates a JsonSink which builds a JSON string.

The string is written to sink.

If indent is supplied, the resulting string will be "pretty printed" with array and object entries on lines of their own and indented by multiples of the indent string. If the indent string is not valid JSON whitespace, the result written to sink will not be valid JSON source.

If asciiOnly is set to true, string values will have all non-ASCII characters escaped. If not, only control characters, quotes and backslashes are escaped.

The returned sink is not reusable. After it has written a single JSON structure, it should not be used again.

Implementation

JsonWriter<String> jsonStringWriter(StringSink sink,
    {String? indent, bool asciiOnly = false}) {
  if (indent == null) return JsonStringWriter(sink, asciiOnly: asciiOnly);
  return JsonPrettyStringWriter(sink, indent, asciiOnly: asciiOnly);
}