createJSONString method

JSString createJSONString({
  1. int indent = 2,
  2. bool autoDispose = true,
})

Creates a JavaScript string containing the JSON serialized representation of a JS value. indent The number of spaces to indent when nesting. If 0, the resulting JSON will not contains newlines. The size of the indent is clamped to 10 spaces. exception A pointer to a JSValueRef in which to store an exception, if any. Pass NULL if you do not care to store an exception.

Implementation

JSString createJSONString({int indent = 2, bool autoDispose = true}) {
  final JSException exception = JSException.create(context);
  final JSStringRef stringRef = JSValueCreateJSONString(
    context.ref,
    _ref,
    indent,
    exception.ref,
  );
  if (exception.shouldThrow) throw exception.error;
  return JSString(stringRef, autoDispose: autoDispose);
}