diff --git a/pkg/yqlib/decoder_json.go b/pkg/yqlib/decoder_json.go index 448550af..a8e1e605 100644 --- a/pkg/yqlib/decoder_json.go +++ b/pkg/yqlib/decoder_json.go @@ -60,7 +60,7 @@ func (dec *jsonDecoder) convertToYamlNode(data *orderedMap) (*yaml.Node, error) } } - var yamlMap = &yaml.Node{Kind: yaml.MappingNode} + var yamlMap = &yaml.Node{Kind: yaml.MappingNode, Tag: "!!map"} for _, keyValuePair := range data.kv { yamlValue, err := dec.convertToYamlNode(&keyValuePair.V) if err != nil { @@ -74,7 +74,7 @@ func (dec *jsonDecoder) convertToYamlNode(data *orderedMap) (*yaml.Node, error) func (dec *jsonDecoder) parseArray(dataArray []*orderedMap) (*yaml.Node, error) { - var yamlMap = &yaml.Node{Kind: yaml.SequenceNode} + var yamlMap = &yaml.Node{Kind: yaml.SequenceNode, Tag: "!!seq"} for _, value := range dataArray { yamlValue, err := dec.convertToYamlNode(value) diff --git a/pkg/yqlib/json_test.go b/pkg/yqlib/json_test.go index 66ec1146..ad1b6bb8 100644 --- a/pkg/yqlib/json_test.go +++ b/pkg/yqlib/json_test.go @@ -78,6 +78,14 @@ const roundTripMultiLineJson = `{ ` var jsonScenarios = []formatScenario{ + { + description: "set tags", + skipDoc: true, + input: "[{}]", + expression: `[.. | type]`, + scenarioType: "roundtrip-ndjson", + expected: "[\"!!seq\",\"!!map\"]\n", + }, { description: "Parse json: simple", subdescription: "JSON is a subset of yaml, so all you need to do is prettify the output",