# convert method

String convert (Object object)

Converts `object` to a JSON String.

Directly serializable values are num, String, bool, and Null, as well as some List and Map values. For List, the elements must all be serializable. For Map, the keys must be String and the values must be serializable.

If a value of any other type is attempted to be serialized, the `toEncodable` function provided in the constructor is called with the value as argument. The result, which must be a directly serializable value, is serialized instead of the original value.

If the conversion throws, or returns a value that is not directly serializable, a JsonUnsupportedObjectError exception is thrown. If the call throws, the error is caught and stored in the JsonUnsupportedObjectError's `cause` field.

If a List or Map contains a reference to itself, directly or through other lists or maps, it cannot be serialized and a JsonCyclicError is thrown.

`object` should not change during serialization.

If an object is serialized more than once, convert may cache the text for it. In other words, if the content of an object changes after it is first serialized, the new values may not be reflected in the result.

## Implementation

    String convert(Object object) =>
        _JsonStringStringifier.stringify(object, _toEncodable, indent);