Structured Data (JSON, YAML) Importer¶
ALFA enables deriving a data model from hierarchical formatted data. Data formatted in JSON, YAML or XML can be used to create a data model.
The structured data importer will analyse the structure and generate a model. The model will contain generated type names as structured data does not contain type information.
The ALFA model importer is run from the command line using the ALFA command-line tool.
Arguments to the CLI.
-i
Parameter has to be specified asstructureddata
-o
The ALFA model is generated into this path.-s namespace=<your namespace>
The structureddata importer requires a settings parameter containing the namespace to be used in the generated model.- Last parameter is the input data file with
.json
, ‘.yaml
or.xml
extension. file is specified as the file to import.
Example¶
Executing the command
alfa -i structureddata -s namespace=mdl -o generated transactions.json
Given a transactions.json
file
{
"Age" : 26,
"Name" : "Joe Bloggs",
"Salary" : 32000.00,
"LoyaltyPoints" : [ 1, 2, 3 ],
"Accounts" : [ {
"Id" : 10901238,
"Currency" : "EUR",
"Balance" : 1200.00
},
{
"Id" : 20901472,
"Currency" : "CHF",
"Balance" : 1200.00
},
{
"Id" : 90321234,
"Currency" : "USD",
"Balance" : 23200.00,
"Type" : "Savings"
} ]
}
The ALFA model below is generated.
namespace mdl
record Rec1 {
Id : int ## 10901238
Currency : string ## "EUR"
Balance : double ## 1200.0
Type : string? ## "Savings"
}
record Rec2 {
Age : int ## 26
Name : string ## "Joe Bloggs"
Salary : double ## 32000.0
LoyaltyPoints : list< int > ## [1,2,3]
Accounts : list< Rec1 >
}
Observations:
- Type names are generated uniquely and can be replaced with more appropriate naming.
- All types are derived correctly
- The ‘Type’ field only exists in one of the nested objects therefore is generated as an optional field
- Comments indicate the data value used to derive the type