The logic to deserialise a structure from *either* JSON or YAML is reused several times and can be easily extracted, which this commit does.