Managed to fix this on my own by adding a layer of abstraction into every place the structs are handled like this:
{ value: {}, order: {} }
And then when tj_encode is called, the order information is used for sorting when writing stuff.
Would be nice to have official support for this, though!