diff --git a/yaml/tojson.nim b/yaml/tojson.nim index 76bd59a..6dafd45 100644 --- a/yaml/tojson.nim +++ b/yaml/tojson.nim @@ -142,7 +142,6 @@ proc constructJson*(s: var YamlStream): seq[JsonNode] let jsonScalar = jsonFromScalar(event.scalarContent, event.scalarTag) levels[levels.high].node[levels[levels.high].key] = jsonScalar - levels[levels.high].key = "" levels[levels.high].expKey = true if event.scalarAnchor != yAnchorNone: anchors[event.scalarAnchor] = jsonScalar @@ -154,12 +153,11 @@ proc constructJson*(s: var YamlStream): seq[JsonNode] case levels[levels.high].node.kind of JArray: levels[levels.high].node.elems.add(level.node) of JObject: - if levels[levels.high].key.len == 0: + if levels[levels.high].expKey: raise newException(YamlConstructionError, "non-scalar as key not allowed in JSON") else: levels[levels.high].node[levels[levels.high].key] = level.node - levels[levels.high].key = "" levels[levels.high].expKey = true else: internalError("Unexpected node kind: " & @@ -173,13 +171,12 @@ proc constructJson*(s: var YamlStream): seq[JsonNode] levels[levels.high].node.elems.add( anchors.getOrDefault(event.aliasTarget)) of JObject: - if levels[levels.high].key.len == 0: + if levels[levels.high].expKey: raise newException(YamlConstructionError, "cannot use alias node as key in JSON") else: levels[levels.high].node.fields.add( levels[levels.high].key, anchors.getOrDefault(event.aliasTarget)) - levels[levels.high].key = "" levels[levels.high].expKey = true else: internalError("Unexpected node kind: " & $levels[levels.high].node.kind)