xref: /aosp_15_r20/external/spdx-tools/docs/jsonloader.md (revision ba677afa8f67bb56cbc794f4d0e378e0da058e16)
1*ba677afaSXin LiSPDX-License-Identifier: CC-BY-4.0
2*ba677afaSXin Li
3*ba677afaSXin Li## Usage
4*ba677afaSXin Li
5*ba677afaSXin LiA json.Unmarshal function on the v2_2.Document struct is defined so that when the JSON is unmarshalled, the function is called and the JSON can be processed in a custom way. Then a new map[string]interface{} is defined which temporarily holds the unmarshalled JSON. The map is then parsed into the v2_2.Document using functions defined for each different section.
6*ba677afaSXin Li
7*ba677afaSXin LiJSON => map[string]interface{} => v2_2.Document
8*ba677afaSXin Li
9*ba677afaSXin Li## Some Key Points
10*ba677afaSXin Li
11*ba677afaSXin Li- The packages have a property "hasFiles" defined in the schema which is an array of the SPDX Identifiers of the files of that package. The parser first parses all the files into the UnpackagedFiles map of the document and then when it parses the Packages, it removes the respective files from the UnpackagedFiles map and places them inside the Files map of the corresponding package.
12*ba677afaSXin Li
13*ba677afaSXin Li- The snippets have a property "snippetFromFile" which has the SPDX identifier of the file to which the snippet is related. Thus the snippets require the files to be parsed before them. Then the snippets are parsed one by one and inserted into the respective files using this property.
14*ba677afaSXin Li
15*ba677afaSXin Li## Assumptions
16*ba677afaSXin Li
17*ba677afaSXin LiThe json file loader in `package jsonloader` makes the following assumptions:
18*ba677afaSXin Li
19*ba677afaSXin Li### Order of appearance of the properties
20*ba677afaSXin Li* The parser does not make any assumptions based on the order in which the properties appear.
21*ba677afaSXin Li
22*ba677afaSXin Li### Annotations
23*ba677afaSXin Li* The JSON SPDX schema does not define the SPDX Identifier property for the annotation object. The parser assumes the SPDX Identifier of the parent property of the currently-being-parsed annotation array to be the SPDX Identifer for all the annotation objects of that array.
24