Jsonnet's docs mention that the +
operator can be used for inheritance, or, as it's worded in the tutorial, to combine objects:
{
a: 1,
b: 2,
}
+
{
a: 3
}
However, I've noticed that - at least in simple cases like the above - simply omitting the +
operator and writing the two consecutive objects separated by whitespace compiles down to the same result. That is, there's no difference in output between the program above and this one:
{
a: 1,
b: 2,
}
{
a: 3
}
I'm puzzled, because I haven't noticed any mention of this implicit object combination in the docs. I also notice that this behaviour seems to be unique to objects and doesn't happen with other types. (In particular, despite Jsonnet drawing inspiration from Python for some of its features, you can't implicitly concatenate strings with whitespace like you can in Python.)
Thus, some questions:
- Is this even intended behaviour, or a bug?
- Is it documented anywhere?
- Are there any behaviour differences between combining objects with the explicit
+
operator and combining them implicitly with whitespace?
A colleague nudges me towards a mention of this in the tutorial, in the Object Orientation section:
So, implicit object combination:
+
, except that it's only usable when the second operand starts with a{
, not when it's a variable.