Force json encoding to ascii

Former-commit-id: b35110f3fed5fedfc03380863ece5c95a2b9d6a7
This commit is contained in:
2023-11-07 12:10:14 +02:00
parent 185b974d13
commit f991886155

View File

@ -6,6 +6,8 @@ import (
"encoding/json" "encoding/json"
"io" "io"
"os" "os"
"strconv"
"strings"
"sync" "sync"
"time" "time"
@ -15,6 +17,14 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
func _UnescapeUnicodeCharactersInJSON(_jsonRaw []byte) ([]byte, error) {
str, err := strconv.Unquote(strings.Replace(strconv.Quote(string(_jsonRaw)), `\\u`, `\u`, -1))
if err != nil {
return nil, err
}
return []byte(str), nil
}
func JSONRecord(sequence *obiseq.BioSequence) []byte { func JSONRecord(sequence *obiseq.BioSequence) []byte {
record := make(map[string]interface{}, 4) record := make(map[string]interface{}, 4)
@ -38,6 +48,12 @@ func JSONRecord(sequence *obiseq.BioSequence) []byte {
log.Panicf("conversion to JSON error on sequence id %s", sequence.Id()) log.Panicf("conversion to JSON error on sequence id %s", sequence.Id())
} }
text, error = _UnescapeUnicodeCharactersInJSON(text)
if error != nil {
log.Panicf("conversion to JSON error on sequence id %s", sequence.Id())
}
return text return text
} }