Updated to add XML as well (below)
So I don’t usually take requests outside of the forum, but @kve asked me an interesting question offline.
He said he wanted to parse JSON in a string field inside an SSRS report as a table.
Well here is how it is done.
Well first I needed a BAQReport and a source of json.
So I made a BAQ, and added one calculated field Calculated_Json
.
You could just add the json directly to that field, and the BAQ will give you one row of it, but i decided to make it a UBAQ, and added a post processing BPM on the GetList
.
Post → Ice.[Company]/JsonSSRSTest.GetList->GrabABCAsJson
//using Newtonsoft.Json;
result.Results.Clear();
result.Results.Add(new ResultsUbaqRow()
{
Calculated_Json = JsonConvert.SerializeObject(
new
{
ABC = Db.ABCCode.ToList()
}).Replace(Session.CompanyID, "Woot!"),
RowIdent = Guid.Empty.ToString()
});
{
"ABC": [
{
"$id": "1",
"Company": "000000",
"ABCCode1": "A",
"CountFreq": 30,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAi6GeQ=",
"SysRowID": "acbcb805-9d15-fca7-e311-33e0dbc8c227",
"EntityKey": {
"$id": "2",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "acbcb805-9d15-fca7-e311-33e0dbc8c227"
}
]
}
},
{
"$id": "3",
"Company": "000000",
"ABCCode1": "B",
"CountFreq": 30,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAAagVU=",
"SysRowID": "acbcb805-9d15-fca7-e311-33e040fdc527",
"EntityKey": {
"$id": "4",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "acbcb805-9d15-fca7-e311-33e040fdc527"
}
]
}
},
{
"$id": "5",
"Company": "000000",
"ABCCode1": "C",
"CountFreq": 60,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAAagVY=",
"SysRowID": "acbcb805-9d15-fca7-e311-33e05124c627",
"EntityKey": {
"$id": "6",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "acbcb805-9d15-fca7-e311-33e05124c627"
}
]
}
},
{
"$id": "7",
"Company": "000000",
"ABCCode1": "D",
"CountFreq": 90,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAAagVc=",
"SysRowID": "acbcb805-9d15-fca7-e311-33e0624bc627",
"EntityKey": {
"$id": "8",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "acbcb805-9d15-fca7-e311-33e0624bc627"
}
]
}
},
{
"$id": "9",
"Company": "Woot!",
"ABCCode1": "A",
"CountFreq": 3,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAST/oU=",
"SysRowID": "8429abd7-2649-4201-ac11-e2df2a9cd71a",
"EntityKey": {
"$id": "10",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "8429abd7-2649-4201-ac11-e2df2a9cd71a"
}
]
}
},
{
"$id": "11",
"Company": "Woot!",
"ABCCode1": "B",
"CountFreq": 7,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAST/oY=",
"SysRowID": "d1840ac1-789e-406a-af2f-9bbbc1e77f70",
"EntityKey": {
"$id": "12",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "d1840ac1-789e-406a-af2f-9bbbc1e77f70"
}
]
}
},
{
"$id": "13",
"Company": "Woot!",
"ABCCode1": "C",
"CountFreq": 14,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAST/oc=",
"SysRowID": "1abd15cd-61d5-4a32-ada8-4869eb7997fd",
"EntityKey": {
"$id": "14",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "1abd15cd-61d5-4a32-ada8-4869eb7997fd"
}
]
}
},
{
"$id": "15",
"Company": "Woot!",
"ABCCode1": "D",
"CountFreq": 30,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAST/og=",
"SysRowID": "ee543161-d93a-4129-9266-882da9ee105f",
"EntityKey": {
"$id": "16",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "ee543161-d93a-4129-9266-882da9ee105f"
}
]
}
},
{
"$id": "17",
"Company": "Woot!",
"ABCCode1": "E",
"CountFreq": 45,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAST/ok=",
"SysRowID": "542e8e01-4449-42af-85a7-3e0c8913f133",
"EntityKey": {
"$id": "18",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "542e8e01-4449-42af-85a7-3e0c8913f133"
}
]
}
},
{
"$id": "19",
"Company": "Woot!",
"ABCCode1": "F",
"CountFreq": 60,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAST/oo=",
"SysRowID": "ac4f5cb9-1f59-4611-8eb4-1ee30c3b713f",
"EntityKey": {
"$id": "20",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "ac4f5cb9-1f59-4611-8eb4-1ee30c3b713f"
}
]
}
},
{
"$id": "21",
"Company": "Woot!",
"ABCCode1": "G",
"CountFreq": 90,
"ExcludeFromCC": false,
"StockValPcnt": 0,
"PcntTolerance": 0,
"CalcPcnt": false,
"CalcQty": false,
"CalcValue": false,
"QtyTolerance": 0,
"ValueTolerance": 0,
"ShipToCustNum": 0,
"SysRevID": "AAAAAAST/os=",
"SysRowID": "1944b5e1-a85d-4220-9173-ce2c77f74d1c",
"EntityKey": {
"$id": "22",
"EntitySetName": "ABCCode",
"EntityContainerName": "ErpContext",
"EntityKeyValues": [
{
"Key": "SysRowID",
"Value": "1944b5e1-a85d-4220-9173-ce2c77f74d1c"
}
]
}
}
]
}
Then I made a simple BAQReport, and generated it for design.
In the designer, I added a new dataset, and chose “Use dataset embedded in my report.”
Edited the query for the DataSet: (only choosing top row and field)
="DECLARE @json NVARCHAR(MAX);
SELECT TOP 1 @json = [Calculated_Json] FROM dbo.[BAQReportResult_" + Parameters!TableGuid.Value + "];
SELECT
jsonParsed.[Company],
jsonParsed.[ABCCode1],
jsonParsed.[CountFreq],
jsonParsed.[ExcludeFromCC],
jsonParsed.[StockValPcnt],
jsonParsed.[PcntTolerance],
jsonParsed.[CalcPcnt],
jsonParsed.[CalcQty],
jsonParsed.[CalcValue],
jsonParsed.[QtyTolerance],
jsonParsed.[ValueTolerance]
FROM OPENJSON(@json, '$.ABC')
WITH (
[Company] NVARCHAR(MAX),
[ABCCode1] NVARCHAR(MAX),
[CountFreq] INT,
[ExcludeFromCC] BIT,
[StockValPcnt] FLOAT,
[PcntTolerance] FLOAT,
[CalcPcnt] BIT,
[CalcQty] BIT,
[CalcValue] BIT,
[QtyTolerance] FLOAT,
[ValueTolerance] FLOAT
) AS jsonParsed;"
Added the fields:
And then proceeded to make the report:
And ran the report:
Thus endeth the demo.