Releases: aditya87/hummus
Releases · aditya87/hummus
v3
Hummus now supports nesting a hummus-tagged struct as a field inside a parent struct, or an array of hummus-tagged structs as fields inside parent structs. Like so:
Example 1
type Inner struct {
A string `hummus:"innerchild.fieldA"`
B string `hummus:"innerchild.fieldB"`
}
input := struct {
C string `hummus:"fieldC"`
I Inner `hummus:"inner"`
}{
C: "C_val",
I: Inner{
A: "A_val",
B: "B_val",
},
}
outJSON, err := hummus.Marshal(input)
This gives us the following JSON:
{
"fieldC": "C_val",
"inner": {
"innerchild": {
"fieldA": "A_val",
"fieldB": "B_val"
}
}
}
Example 2
type Inner struct {
A string `hummus:"innerchild.fieldA"`
B string `hummus:"innerchild.fieldB"`
}
input := struct {
C string `hummus:"fieldC"`
I []Inner `hummus:"inner"`
}{
C: "C_val",
I: []Inner{
{
A: "A_val1",
B: "B_val1",
},
{
A: "A_val2",
B: "B_val2",
},
},
}
outJSON, err := hummus.Marshal(input)
Gives us the following JSON:
{
"fieldC": "C_val",
"inner": [
{
"innerchild": {
"fieldA": "A_val1",
"fieldB": "B_val1"
}
},
{
"innerchild": {
"fieldA": "A_val2",
"fieldB": "B_val2"
}
}
]
}
v2
Hummus now handles out-of-order array tags. E.g.
input := struct {
Brand0 string `hummus:"brands[2]"`
Brand1 string `hummus:"brands[0]"`
Brand2 string `hummus:"brands[1]"`
}{
Brand0: "sabra",
Brand1: "athenos",
Brand2: "whole-foods",
}
Marshalling this will return
{
"brands": ["athenos", "whole-foods", "sabra"]
}
as expected.