mirror of
https://github.com/metabarcoding/obitools4.git
synced 2025-06-29 16:20:46 +00:00
Force json encoding to ascii
Former-commit-id: b35110f3fed5fedfc03380863ece5c95a2b9d6a7
This commit is contained in:
@ -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
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user