diff options
author | Keith Zantow <kzantow@gmail.com> | 2022-10-06 19:34:47 -0400 |
---|---|---|
committer | Keith Zantow <kzantow@gmail.com> | 2022-10-06 19:34:47 -0400 |
commit | 6fda8118533aec0a73ca431cb32c7ca951b58200 (patch) | |
tree | 7822903eb502060bbea9e618b33665c027c0d701 /json/parser.go | |
parent | 993e4915516e773859e9947e9fe815f08a25ed5a (diff) | |
download | spdx-tools-6fda8118533aec0a73ca431cb32c7ca951b58200.tar.gz |
chore: Add v2.3 data model and JSON support
Signed-off-by: Keith Zantow <kzantow@gmail.com>
Diffstat (limited to 'json/parser.go')
-rw-r--r-- | json/parser.go | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/json/parser.go b/json/parser.go index 5c9e6f4..ee7915d 100644 --- a/json/parser.go +++ b/json/parser.go @@ -8,6 +8,7 @@ import ( "io" "github.com/spdx/tools-golang/spdx/v2_2" + "github.com/spdx/tools-golang/spdx/v2_3" ) // Load2_2 takes in an io.Reader and returns an SPDX document. @@ -27,3 +28,21 @@ func Load2_2(content io.Reader) (*v2_2.Document, error) { return &doc, nil } + +// Load2_3 takes in an io.Reader and returns an SPDX document. +func Load2_3(content io.Reader) (*v2_3.Document, 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 v2_3.Document + err = json.Unmarshal(buf.Bytes(), &doc) + if err != nil { + return nil, err + } + + return &doc, nil +} |