1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
package loading
import (
"encoding/json"
"errors"
"path/filepath"
)
// JSONMatcher matches json for a file loader.
func JSONMatcher(path string) bool {
ext := filepath.Ext(path)
return ext == ".json" || ext == ".jsn" || ext == ".jso"
}
// JSONDoc loads a json document from either a file or a remote url.
func JSONDoc(path string, opts ...Option) (json.RawMessage, error) {
data, err := LoadFromFileOrHTTP(path, opts...)
if err != nil {
return nil, errors.Join(err, ErrLoader)
}
return json.RawMessage(data), nil
}
|