forked from elastic/beats
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Disable HTML escaping during JSON Marshaling
By default the golang JSON Marshaller escapes HTML entries. As this is not required for beats this is disabling this option. * Unification of json marshalling Closes elastic#2581
- Loading branch information
Showing
4 changed files
with
39 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package common | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
|
||
"fmt" | ||
) | ||
|
||
// JSONEncode encodes the given interface to JSON | ||
func JSONEncode(data interface{}, pretty bool) ([]byte, error) { | ||
|
||
buffer := &bytes.Buffer{} | ||
enc := json.NewEncoder(buffer) | ||
enc.SetEscapeHTML(true) | ||
|
||
enc.SetIndent("", "") | ||
if pretty { | ||
enc.SetIndent("", " ") | ||
} | ||
|
||
err := enc.Encode(data) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to convert the data to JSON (%v): %#v", err, data) | ||
} | ||
|
||
return buffer.Bytes(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters