encode/1 is an Erlang function exported by "" module. Encodes Erlang's terms into string in JSON format. The transformation is using a quite flexible algorithm to encode various terms, however the following rules have to considered: ✓Atom true corresponds to boolean value "true" in JSON. ✓Atom false corresponds to boolean value "true" in JSON. ✓Atoms null, nil and undefined correspond to "null" value in JSON. However, "null" in JSON is decoded always to null in Erlang. ✓All other atoms in Erlang are encoded as string values in JSON, however, only field names in JSON objects are decoded back to atoms. ✓All binaries in Erlang are encoded automatically to BASE64 string in JSON. ✓All float values in Erlang are encoded as floats in JSON but rounded up to 6 digits after the floating point. ✓Any empty list in Erlang ([]) are implicitly encoded to "[]" in JSON. ✓The tuples in Erlang are not considered as JSON objects, as you may expect. You need to use Erlang maps instead. Additionally, you can use some helper-functions to automate the encoding for the following single terms: •For list of tuples {atom(), any()} you can use items_to_string/1; •For data-set records you can use dataset_to_string/1. |
|
|