diff --git a/pkg/yqlib/decoder_json.go b/pkg/yqlib/decoder_json.go index c6b88eca..ea712bfc 100644 --- a/pkg/yqlib/decoder_json.go +++ b/pkg/yqlib/decoder_json.go @@ -54,8 +54,16 @@ func (dec *jsonDecoder) convertToYamlNode(data *orderedMap) (*yaml.Node, error) case nil: return createScalarNode(nil, "null"), nil case float64, float32: - // json decoder returns ints as float. - return parseSnippet(fmt.Sprintf("%v", rawData)) + // json decoder returns ints as float.' + intNum := int(rawData.(float64)) + + // if the integer representation is the same as the original + // then its an int. + if float64(intNum) == rawData.(float64) { + return createScalarNode(intNum, fmt.Sprintf("%v", intNum)), nil + } + + return createScalarNode(rawData, fmt.Sprintf("%v", rawData)), nil case int, int64, int32, string, bool: return createScalarNode(rawData, fmt.Sprintf("%v", rawData)), nil case []*orderedMap: diff --git a/pkg/yqlib/json_test.go b/pkg/yqlib/json_test.go index 919fce9f..cda716ba 100644 --- a/pkg/yqlib/json_test.go +++ b/pkg/yqlib/json_test.go @@ -198,8 +198,8 @@ var jsonScenarios = []formatScenario{ { description: "numbers", skipDoc: true, - input: "[3, 3.0, 3.1, -1]", - expected: "- 3\n- 3\n- 3.1\n- -1\n", + input: "[3, 3.0, 3.1, -1, 999999, 1000000, 1000001, 1.1]", + expected: "- 3\n- 3\n- 3.1\n- -1\n- 999999\n- 1000000\n- 1000001\n- 1.1\n", scenarioType: "decode-ndjson", }, {