Convert
Vision elements have what is called the flat representation, which is a data layout designed for exporting the element. If you want to export the element into a custom-designed file format, you will probably first want to convert it to flat, and then save each of the fields of the flat object to the file.
- Ve → Flat → Custom file format: Convert to flat, then save the flat representation with a custom-made file format.
The following operations are equivalent in terms of the result:
- Ve → Flat → JSON string → JSON file: Convert to flat, convert the flat object to JSON (string), then save the JSON string to a file.
- Ve → JSON string → JSON file: Convert directly to JSON (string), save the JSON string to a file.
- Ve → JSON file: Use a built-in function to save the vision element to a file.
The flat object has the following characteristics:
- All data is accessible through first-level fields (thus the name "flat").
- It contains exactly the same data as the original vision element and the conversions are reversible: A converstion "to flat" and then "from flat" will result in the same vision element.
- It is directly convertable to JSON: Converting a vision element to flat, and the the flat object to JSON will have the same result as converting the vision element directly to JSON.
- Cannot be used in the functions of the vision elements library. It has to be first converted back to a vision element.
Conversion to flat
veToFlat()
Conversion of a vision element to flat object.
function veToFlat(ve: VisionElement): IVisionElementFlat;
listToFlat()
Conversion of a list of vision elements to flat.
function listToFlat(veList: VisionElement[]): IVisionElementFlat[];
dictionaryToFlat()
Conversion of a dictionary of vision elements to flat.
function dictionaryToFlat(dict: Dictionary): DictionaryFlat;
Conversion from flat
veFromFlat()
Conversion of a flat object to a vision element.
function veFromFlat(flat: IVisionElementFlat): IVisionElementFlat;
listFromFlat()
Conversion of a list of flat objects to a list of vision elements.
function listFromFlat(flatList: IVisionElementFlat[]): IVisionElement[];
dictionaryFromFlat()
Conversion of a dictionary of flat objects to a dictionary of vision elements.
function dictionaryFromFlat(flatDict: DictionaryFlat[]): IVisionElementFlat[];
Conversion to JSON
veToJson()
Conversion of a vision element to a JSON string.
function veToJson(ve: VisionElement): string;
flatToJson()
Conversion of a flat object to a JSON string.
function flatToJson(flat: IVisionElementFlat): string;
listToJson()
Conversion of a list of vision elements to a JSON string.
function listToJson(veList: VisionElement[]): string;
dictionaryToJson()
Conversion of a dictionary of vision elements to a JSON string.
function dictionaryToJson(dict: Dictionary): string;
Conversion from JSON
veFromJson()
Parses a JSON string to a vision element. If the string is not a valid JSON or a not a valid vision element, an error is thrown.
function veFromJson(json: string): VisionElement;
flatFromJson()
Parses a JSON string to flat value. If the string is not a valid JSON or a not a valid flat value, an error is thrown.
function flatFromJson(json: string): IVisionElementFlat;
listFromJson()
Parses a JSON string to a list of vision elements. If the string is not a valid JSON or a not a valid list of vision elements, an error is thrown.
function listFromJson(json: string): VisionElement[];
dictionaryFromJson()
Parses a JSON string to a dictionary of vision elements. If the string is not a valid JSON or a not a valid dictionary of vision elements, an error is thrown.
function dictionaryFromJson(json: string): Dictionary;
Conversion to file
veToFile()
Writes a single vision element to a file (data is internally stored as JSON).
function veToFile(ve: VisionElement, filePath: string): void;
flatToFile()
Writes a single flat object to a file (data is internally stored as JSON).
function flatToFile(float: IVisionElementFlat, filePath: string): void;
listToFile()
Writes a list of vision elements to file (data is internally stored as JSON).
function listToFile(veList: VisionElement[], filePath: string): void;
flatToFile()
Writes a dictionary of vision elements to file (data is internally stored as JSON).
function dictionaryToFile(dict: Dictionary, filePath: string): void;
Conversion from file
veFromFile()
Reads a single vision element from file. If the file doesn't contain a valid vision element, an error is thrown.
function veFromFile(filePath: string): VisionElement;
flatFromFile()
Reads a single flat object from file. If the file doesn't contain a valid flat object, an error is thrown.
function flatFromFile(filePath: string): IVisionElementFlat;
listFromFile()
Reads a list of vision elements from file. If the file doesn't contain a valid list of vision elements, an error is thrown.
function listFromFile(filePath: string): VisionElement[];
dictionaryFromFile()
Reads a dictionary from file. If the file doesn't contain a valid dictionary, an error is thrown.
function dictionaryFromFile(filePath: string): Dictionary;