Allow build without json and xml support (#1556)

* Refactor ordered_map into separate files

Separate json and xml, from the regular yaml.

Makes it possible to compile, without those...

* Refactor encoder and decoder creation

Use more consistent parameters vs globals

Return errors instead of calling panic()

* Allow build without json and xml support
This commit is contained in:
Anders Björklund
2023-03-01 13:19:06 +11:00
committed by GitHub
parent 62d167c141
commit cf8cfbd865
22 changed files with 338 additions and 213 deletions
+2 -15
View File
@@ -1,3 +1,5 @@
//go:build !yq_nojson
package yqlib
import (
@@ -14,21 +16,6 @@ type jsonEncoder struct {
UnwrapScalar bool
}
func mapKeysToStrings(node *yaml.Node) {
if node.Kind == yaml.MappingNode {
for index, child := range node.Content {
if index%2 == 0 { // its a map key
child.Tag = "!!str"
}
}
}
for _, child := range node.Content {
mapKeysToStrings(child)
}
}
func NewJSONEncoder(indent int, colorise bool, unwrapScalar bool) Encoder {
var indentString = ""