jsonScript function
A <script type="application/json"> holding data as JSON, the safe
way to give a script server data: <, >, &, U+2028 and U+2029 are
written as \u escapes, so no value can close the element. Read it with
JSON.parse(document.getElementById(id).textContent).
Implementation
Element jsonScript(
Object? data, {
required String id,
String? classes,
Map<String, Object?> attributes = const {},
}) => _tag(
'script',
[RawHtml(_scriptSafeJson(jsonEncode(data)))],
id,
classes,
{'type': 'application/json', ...attributes},
);