/AutoHotkey-SerDes

Serialize / de-serialize an AutoHotkey object structure

Primary LanguageAutoHotkey

SerDes

Serialize / de-serialize an AutoHotkey object structure.

Requires AHK v1.1+ OR v2.0-a049+

License: WTFPL


Serialize

Syntax

str   := SerDes( obj [ ,, indent := "" ] )
bytes := SerDes( obj, outfile [ , indent := "" ] )

Parameters

str      [retval]   - String representation of the object
bytes    [retval]   - Bytes written to 'outfile'.
obj      [in]       - AHK object to serialize.
outfile  [in, opt]  - The file to write to. If no absolute path is specified, %A_WorkingDir% is used.
indent   [in, opt]  - If indent is an integer or string, then array elements and object members will
                      be pretty-printed with that indent level. Blank(""), the default, OR 0, selects
                      the most compact representation. Using an integer indent indents that many spaces
                      per level. If indent is a string, (such as "`t"), that string is used to indent
                      each level. Negative integer is treated as positive.

Deserialize

Syntax

obj   := SerDes( src )

Parameters

obj      [retval]   - An AHK object
src      [in]       - Either a 'SerDes()' formatted string or the path to the file containing 'SerDes()' formatted text.

Remarks:

  • Serilaized output is similar to JSON except for escape sequences which follows AHK's specification. Also, strings, numbers and objects are allowed as object/{} keys unlike JSON which restricts it to string data type only.
  • Non-standard AHK objects such as COM, Func, FileObject, RegExMatchObject are not supported.
  • Object references, including circular ones, are supported and notated as $n, where n is the 1-based index of the referenced object in the heirarchy tree when encountered during enumeration (for-loop) OR as it appears from left to right (for string representation) as marked by an opening brace{ or bracket[.
1         2
{ "key1": ["Hello World"], "key2": $2 } // -> $2 references the object stored in 'key1'