aboutsummaryrefslogtreecommitdiff
path: root/json/parser.go
diff options
context:
space:
mode:
Diffstat (limited to 'json/parser.go')
-rw-r--r--json/parser.go29
1 files changed, 29 insertions, 0 deletions
diff --git a/json/parser.go b/json/parser.go
new file mode 100644
index 0000000..387b5b0
--- /dev/null
+++ b/json/parser.go
@@ -0,0 +1,29 @@
+// SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
+
+package spdx_json
+
+import (
+ "bytes"
+ "encoding/json"
+ "io"
+
+ "github.com/spdx/tools-golang/spdx"
+)
+
+// Load2_2 takes in an io.Reader and returns an SPDX document.
+func Load2_2(content io.Reader) (*spdx.Document2_2, error) {
+ // convert io.Reader to a slice of bytes and call the parser
+ buf := new(bytes.Buffer)
+ _, err := buf.ReadFrom(content)
+ if err != nil {
+ return nil, err
+ }
+
+ var doc spdx.Document2_2
+ err = json.Unmarshal(buf.Bytes(), &doc)
+ if err != nil {
+ return nil, err
+ }
+
+ return &doc, nil
+}