xref: /aosp_15_r20/external/spdx-tools/docs/jsonsaver.md (revision ba677afa8f67bb56cbc794f4d0e378e0da058e16)
1*ba677afaSXin LiSPDX-License-Identifier: CC-BY-4.0
2*ba677afaSXin Li
3*ba677afaSXin Li## Working
4*ba677afaSXin Li
5*ba677afaSXin LiThe SPDX document is converted to map[string]interface{} and then the entire map is converted to JSON using a single json.MarshalIndent function call. The saver uses temporary memory to store all the files (Packaged and Unpackaged) together in a single data structure in order to comply with the JSON schema defined by SPDX.
6*ba677afaSXin Li
7*ba677afaSXin Liv2_2.Document => map[string]interface{} => JSON
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 saver iterates through the files of a package and inserts all the SPDX Identifiers of the files in the "hasFiles" array. In addition it adds each file to a temporary storage map to store all the files of the entire document at a single place.
12*ba677afaSXin Li
13*ba677afaSXin Li- The files require the packages to be saved before them in order to ensure that the packaged files are added to the temporary storage before the files are saved.
14*ba677afaSXin Li
15*ba677afaSXin Li- The snippets are saved after the files and a property "snippetFromFile" identifies the file containing each snippet.
16*ba677afaSXin Li
17*ba677afaSXin Li## Assumptions
18*ba677afaSXin Li
19*ba677afaSXin LiThe json file loader in `package jsonsaver` makes the following assumptions:
20*ba677afaSXin Li
21*ba677afaSXin Li### Order of appearance of the properties
22*ba677afaSXin Li* The saver does not make any pre-assumptions based on the order in which the properties are saved.
23*ba677afaSXin Li
24*ba677afaSXin Li### Annotations
25*ba677afaSXin Li* The JSON SPDX schema does not define the SPDX Identifier property for the annotation object. The saver inserts the annotation inside the element whose SPDX Identifier matches the annotation's SPDX Identifier.
26*ba677afaSXin Li
27*ba677afaSXin Li### Indentation
28*ba677afaSXin Li* The jsonsaver uses the MarshalIndent function with "" as the prefix and "\t" as the indent character, passed as function parameters.
29