$nl
"Some options can control the formatting of the result:"
{ $table
- { { $link json-allow-nans? } "Allow special floating-points: NaN, Infinity, -Infinity." }
- { { $link json-friendly-keys? } "Convert - to _ in tuple slots and hashtable keys" }
- { { $link json-coerce-keys? } "Coerce hashtable keys into strings" }
- { { $link json-escape-slashes? } "Escape forward slashes inside strings" }
- { { $link json-escape-unicode? } "Escape unicode values inside strings" }
+ { { $link json-allow-fp-special? } "Allow special floating-points: NaN, Infinity, -Infinity" }
+ { { $link json-friendly-keys? } "Convert - to _ in tuple slots and hashtable keys" }
+ { { $link json-coerce-keys? } "Coerce hashtable keys into strings" }
+ { { $link json-escape-slashes? } "Escape forward slashes inside strings" }
+ { { $link json-escape-unicode? } "Escape unicode values inside strings" }
}
}
{ $see-also >json } ;
[ H{ { json-null 1 } } >json ] unit-test
{ """{"Infinity":1}""" }
-[ t json-allow-nans? [ H{ { 1/0. 1 } } >json ] with-variable ] unit-test
+[ t json-allow-fp-special? [ H{ { 1/0. 1 } } >json ] with-variable ] unit-test
{ """{"-Infinity":1}""" }
-[ t json-allow-nans? [ H{ { -1/0. 1 } } >json ] with-variable ] unit-test
+[ t json-allow-fp-special? [ H{ { -1/0. 1 } } >json ] with-variable ] unit-test
{ """{"NaN":1}""" }
-[ t json-allow-nans? [ H{ { NAN: 333 1 } } >json ] with-variable ] unit-test
+[ t json-allow-fp-special? [ H{ { NAN: 333 1 } } >json ] with-variable ] unit-test
{
"\"\\u0000\\u0001\\u0002\\u0003\\u0004\\u0005\\u0006\\u0007\\b\\t\\n\\u000b\\f\\r\\u000e\\u000f\\u0010\\u0011\\u0012\\u0013\\u0014\\u0015\\u0016\\u0017\\u0018\\u0019\\u001a\\u001b\\u001c\\u001d\\u001e\\u001f\""
namespaces sequences strings tr words ;
IN: json.writer
-SYMBOL: json-allow-nans?
-f json-allow-nans? set-global
+SYMBOL: json-allow-fp-special?
+f json-allow-fp-special? set-global
SYMBOL: json-friendly-keys?
t json-friendly-keys? set-global
: float>json ( float -- string )
dup fp-special? [
- json-allow-nans? get [ json-error ] unless
+ json-allow-fp-special? get [ json-error ] unless
{
{ [ dup fp-nan? ] [ drop "NaN" ] }
{ [ dup 1/0. = ] [ drop "Infinity" ] }