JsonStream$

Used to manipulate a WorkQuery into a JSON type

Description:

# JsonStream$

This Foreign function converts the Work Query into a single stream of JSON data. It has only one parameter, Options, which is documented below.

# SaveJsonFile

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.

# Options

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 {

* **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]"}}
        }]
    ]