0
votes

Let us consider a tcl data as follows:

set arr {a {{c 1} {d {2 2 2} e 3}} b {{f 4 g 5}}}

Converted into Json format using huddle module:

set json_arr [huddle jsondump [huddle compile {dict * {list {dict d list}}} $arr] {} {}]
puts $json_arr
{"a":[{"c":1},{"d":[2,2,2],"e":3}],"b":[{"f":4,"g":5}]}

Here I have specified the structure of tcl array as {dict * {list {dict d list}}} . But, I want to automate this part (don't want to manually find the structure).

I am able to determine the type of string, list and dict but unable to find the type of such variable or more complex than this.

Please post any suggestion or other way for the same.

1

1 Answers

2
votes

Tcl is typeless, or "type free" if you will. That's one of its strengths, but it also means that you will have to do some work when interfacing Tcl with typed formats like JSON.

You can’t automatically create a complete and reliable generic type description of arbitrary Tcl data.

The point of huddle is to assist in adding type information to Tcl data while preserving its "processabiliy", but your understanding of the data model is still needed and must be manually expressed as code.

You can of course automatically create a specific type description of domain-specific Tcl data. The data in your example seems unintelligible, but if there are rules that always hold (strings of integers are always integer scalars or integer arrays, etc), those rules can be used to drive a huddle format generator.