Serializing data from Tcl

Tcl still is in use in a number of environments like embedded devices. However, looking at Tcl code fragments reminded me of why I gave up on Tcl many years ago. I can't really recommend spending much time in Tcl.

However, if Tcl is your only choice for "primary information", then you need to translate the information from a Tcl structure into another format. Potential candidates for this are XML, JSON, or YAML. I think JSON is a little better for most simple data structures you may find in Tcl, but pick your poison.

In addition to the TclXML library, you can also serialize Tcl structures into JSON using a Tcl library called huddle ( Huddle has a jsondump command which is described as this :

  1. Huddle provides a generic Tcl-based serialization format
  2. The entries in that format are tagged with simple type information
  3. The currently the known types are 'L' for list, and 'D' for dict.
  4. When converting huddle-notation to other serialization formats like JSON or YAML this type information is used to select the proper notation.
  5. And when going from JSON/YAML/... to huddle their notation can be used to select the proper huddle type.
  6. In that manner huddle can serve as a common intermediary format.
    The nice thing about its notation that Tcl can read this format directly (list/dict commands) without the need for a special parser.

This is the nice thing about standards. You can choose whichever one you want ;-)