JSON encoder and decoder


_ <- fat.extra.json


Name Signature Brief
toJson (x: Any): Text Build json from native types
fromJson (json: Text): Any Parse a json to native types

Usage Notes

"With great power comes great responsibility" -Peter Parker

Since FatScript alternatively accepts JSON-like syntax, fromJson actually uses FatScript internal lexer/parser via eval, which is blazing fast, but may or not yield exactly what one is expecting from a JSON parser.

For example, once the bellow fragment is parsed, since null in FatScript is absence of value, there would be no entry declarations for "prop":

"prop": null

Therefore, reading with fromJson and writing back with toJson is not necessarily an idempotent operation.

Heads Up!

The fromJson method should be perfectly fine and safe for reading config files or reading back data stored via toJson.

However, since fromJson ingests data via $eval a specially crafted file could implement a FatScript program and run arbitrary code!

If reading JSON files from an unknown source, to be on the safe side, you should make your own safety-driven parser.

if you have written an alternative JSON parser in FatScript and would like to share the reference here, see contributing document

See also

results matching ""

    No results matching ""