Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
liggitt committed Oct 20, 2023
1 parent 65d71bb commit c79df88
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions yaml.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,13 +110,13 @@ func JSONToYAML(j []byte) ([]byte, error) {
// number type, so we can preserve number type throughout this process.
err := yaml.Unmarshal(j, &jsonObj)
if err != nil {
return nil, fmt.Errorf("error converting JSON to YAML: %w", err)
return nil, err
}

// Marshal this object into YAML.
yamlBytes, err := yaml.Marshal(jsonObj)
if err != nil {
return nil, fmt.Errorf("error converting JSON to YAML: %w", err)
return nil, err
}

return yamlBytes, nil
Expand Down Expand Up @@ -155,7 +155,7 @@ func yamlToJSONTarget(yamlBytes []byte, jsonTarget *reflect.Value, unmarshalFn f
var yamlObj interface{}
err := unmarshalFn(yamlBytes, &yamlObj)
if err != nil {
return nil, fmt.Errorf("error converting YAML to JSON: %w", err)
return nil, err
}

// YAML objects are not completely compatible with JSON objects (e.g. you
Expand All @@ -164,13 +164,13 @@ func yamlToJSONTarget(yamlBytes []byte, jsonTarget *reflect.Value, unmarshalFn f
// incompatibilties happen along the way.
jsonObj, err := convertToJSONableObject(yamlObj, jsonTarget)
if err != nil {
return nil, fmt.Errorf("error converting YAML to JSON: %w", err)
return nil, err
}

// Convert this object to JSON and return the data.
jsonBytes, err := json.Marshal(jsonObj)
if err != nil {
return nil, fmt.Errorf("error converting YAML to JSON: %w", err)
return nil, err
}
return jsonBytes, nil
}
Expand Down

0 comments on commit c79df88

Please sign in to comment.