SaveJsonFile
Takes two parameters, FileName, Options
Description:
This command saves the Work Query as JSON data. The first parameter is the output filename, the second parameter is Options, which is documented below.
Usage:
The following Options are available, and may be space separated for valid combinations. The default used if blank is just the single value of "Array".
- Header - Includes the Field Names as a Header Row. Intended to be used with Array when the Field Names are not fixed or predetermined.
- Array - Outputs each Record in the Query as a JSON Array, namely uses [ ] to wrap the records, and each field is quoted and comma separated. Simple numbers remain unquoted.
- Object - Outputs each Record in the Query as a JSON Object, namely uses { } to wrap the records, and each field is named in quotes, followed by a : then the value in quotes. Simple numbers remain unquoted. If used without Array the first Field in the Query will be the Object Name, if Array is used then an Array of Objects will be returned.
- Embed - Existing JSON data within the Fields is left untouched. In order to not be touched, a Field must start with [ or {
- WebSafe - Apply the WebSafe function to the data before applying the JSON escape encoding
- RecoverHtml - Apply the RecoverHtml function to the data before applying the JSON escape encoding
- RecoverHtmlObj - Apply the RecoverHtmlObj function to the data before applying the JSON escape encoding
- RecoveryMOX - Apply the RecoverMOX function to the data before applying the JSON escape encoding
- FixNumbers - If a valid number is found that doesn't fit JSON's number format requirements, such as .123 must be 0.123, and 0123 must be just 123, fix these numbers to match JSON's requirements. If this option is not used, such numbers will be preserved as-is in quotes.
- Format - Output with extra whitespace to make it more easily read by humans
Example:
LoadTable "MemTab.Person"
LTrimFields "MemTab.Person."
[New] Buff
Buff | JsonStream$ "Object"
SetNew "Embeded", `Buff
Buff | JsonStream$ "Object Array Format Embed"
SaveFile "Test1.json", Buff
SaveJsonFile "Test2.json", "Object Format Embed"
HtmlAlert "&success", "All ok! All Done."
Output:
[
[{
"Alias": 10101,
"Firstname": "DB Admin",
"Lastname": null,
"Birthdate": null,
"Gender": "Male",
"Email": "[email protected]",
"Embeded": {"10101":{"Firstname":"DB Admin","Lastname":null,"Birthdate":null,"Gender":"Male","Email":"[email protected]"},"10102":{"Firstname":"TrainerBob","Lastname":"Moxie","Birthdate":null,"Gender":"Male","Email":"[email protected]"}}
}],
[{
"Alias": 10102,
"Firstname": "TrainerBob",
"Lastname": "Moxie",
"Birthdate": null,
"Gender": "Male",
"Email": "[email protected]",
"Embeded": {"10101":{"Firstname":"DB Admin","Lastname":null,"Birthdate":null,"Gender":"Male","Email":"[email protected]"},"10102":{"Firstname":"TrainerBob","Lastname":"Moxie","Birthdate":null,"Gender":"Male","Email":"[email protected]"}}
}]
]