# DataSchema.JSON

DataSchema.JSON normalizes arbitrary JSON data against a given schema into an object with known properties.

#### Basic example

###### Data

    {
        "total":10,
        "results":[
            {"n":1, "fname":"George", "lname":"Washington"},
            {"n":2, "fname":"John", "lname":"Adams"},
            {"n":3, "fname":"Thomas", "lname":"Jefferson"},
            {"n":4, "fname":"James", "lname":"Madison"},
            {"n":5, "fname":"James", "lname":"Monroe"},
            {"n":6, "fname":"John", "mname":"Quincy", "lname":"Adams"},
            {"n":7, "fname":"Andrew", "lname":"Jackson"},
            {"n":8, "fname":"Martin", "lname":"Van Buren"},
            {"n":9, "fname":"William", "mname":"Henry", "lname":"Harrison"},
            {"n":10, "fname":"John", "lname":"Tyler"}
        ]
    }

###### Schema

    {
        metaFields: {total:"total"},
        resultListLocator: "results",
        resultFields: [{key:"n"}, {key:"fname"}, {key:"lname"}]
    }

###### Normalized data

#### Complex example

###### Data

    {
        "profile":{
            "current":160,
            "target":150
        },
        "reference": [
            {
                "category":"exercise",
                "type":"expenditure",
                "activities":[
                    {"name":"biking", "calories":550},
                    {"name":"golf", "calories":1000},
                    {"name":"running", "calories":650},
                    {"name":"swimming", "calories":650},
                    {"name":"walking", "calories":225}
                ]
            },
            {
                "category":"nutrition",
                "type":"intake",
                "fruit":[
                    {"name":"apple", "calories":70},
                    {"name":"banana", "calories":70},
                    {"name":"orange", "calories":90},
                ],
                "vegetables":[
                    {"name":"baked potato", "calories":150},
                    {"name":"broccoli", "calories":50},
                    {"name":"green beans", "calories":30}
                ]
            }
        ],
        "program": [
            {
                "category":"exercise",
                "schedule":[
                    {"day":"sunday", "activity":"swimming"},
                    {"day":"monday", "activity":"running"},
                    {"day":"tuesday", "activity":"biking"},
                    {"day":"wednesday", "activity":"running"},
                    {"day":"thursday", "activity":"swimming"},
                    {"day":"friday", "activity":"running"},
                    {"day":"saturday", "activity":"golf"}
                ]
            },
            {
                "category":"diet",
                "schedule":[
                ]
            }
        ]
    }

###### Schema

    {
        metaFields: {current:"profile.current", target:"profile.target",
            reference:"reference[0].activities"},
        resultListLocator: "program[0].schedule",
        resultFields: [{key:"day"}, {key:"activity"}]
    }

###### Normalized data