I need to convert the following table:
Into a JSON
format, like:
{
"Inputs": {
"input1": {
"ColumnNames": [
"age",
"workclass",
"fnlwgt",
"education",
"education-num",
"marital-status",
"occupation",
"relationship",
"race",
"sex",
"capital-gain",
"capital-loss",
"hours-per-week",
"native-country"
],
"Values": [
[
"0",
"value",
"0",
"value",
"0",
"value",
"value",
"value",
"value",
"value",
"0",
"0",
"0",
"value"
],
[
"0",
"value",
"0",
"value",
"0",
"value",
"value",
"value",
"value",
"value",
"0",
"0",
"0",
"value"
]
]
}
},
"GlobalParameters": {}
}
This is supposed to be used as the body of a POST
request to a web service.
So, I've tried applying the following function to the table above:
(InputData) =>
let
JsonOutput = Json.FromValue(InputData),
OutputText = Text.FromBinary(JsonOutput)
in
OutputText
This is the full code:
let
Origem = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("HY2xDsIwDET/JTOWGtoSMcIOC0IMVQcrMdSS00huVIm/x2G4e3e64abJ9Wd3cI+KleBTdsshjP5kvGJcSIpuln1vdqedFDKqMiXrl5QhCilHlDaXCrzCGzPL1/pr4UrGG0rD0YfB0JmGZs/V5gT/583N8w8=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [age = _t, workclass = _t, fnlwgt = _t, education = _t, #"education-num" = _t, #"marital-status" = _t, occupation = _t, relationship = _t, race = _t, sex = _t, #"capital-gain" = _t, #"capital-loss" = _t, #"hours-per-week" = _t, #"native-country" = _t]),
#"Tipo Alterado" = Table.TransformColumnTypes(Origem,{{"age", Int64.Type}, {"workclass", type text}, {"fnlwgt", Int64.Type}, {"education", type text}, {"education-num", Int64.Type}, {"marital-status", type text}, {"occupation", type text}, {"relationship", type text}, {"race", type text}, {"sex", type text}, {"capital-gain", Int64.Type}, {"capital-loss", Int64.Type}, {"hours-per-week", Int64.Type}, {"native-country", type text}}),
Output = GetJson(#"Tipo Alterado")
in
Output
But this is returning:
[{"age":39,"workclass":"State-gov","fnlwgt":77516,"education":"Bachelors","education-num":13,"marital-status":"Never-married","occupation":"Adm-clerical","relationship":"Not-in-family","race":"White","sex":"Male","capital-gain":2174,"capital-loss":0,"hours-per-week":40,"native-country":"United-States"}]