Hi there, everyone.
I'm busy with a process where we extract data from a SQL table to JSON format. My current struggle is how to get the schema to show properly. It should look something like this.
{
"company": "mrpg",
"journals": [
{
"MRPRedWorldId": "Id1",
"JournalName": "GRN",
"JournalDescription": "Description",
"lines": [
{
This is the code I'm using in a stored procedure:
SELECT
'mrpg' AS company,
MRPRedworldId = journals.GLExtractId,
JournalName = RTRIM(journals.JournalName),
JournalDescription = 'Description',
lines.LineNumber,
lines.CreditAmount,
lines.AccountDisplayValue,
lines.[Description],
lines.TransDate,
lines.CurrencyCode,
lines.DebitAmount,
lines.AccountType
FROM [working].[DBRSalesWorking] AS company
JOIN [working].[DBRSalesWorking] AS journals
ON company.DivisionId = journals.DivisionId
AND company.GLExtractId = journals.GLExtractId
JOIN [working].[DBRSalesWorking] AS lines
ON journals.DivisionId = lines.DivisionId
AND journals.GLExtractId = lines.GLExtractId
AND journals.LineNumber = lines.LineNumber
WHERE lines.GLExtractId = 24447
FOR JSON PATH, ROOT ('company')
The result is:
{"
company":[{
"company":"mrpg",
"MRPRedworldId":24447,
"JournalName":"GNJ",
"JournalDescription":"Description",
"LineNumber":1,
"CreditAmount":129992.43,
"AccountDisplayValue":"31005030-800000-10280",
"Description":"DBR 393 CASH TAKEN INC VAT EX DBR",
"TransDate":"20200110",
"CurrencyCode":"ZAR",
"DebitAmount":0.00,
"AccountType":"Ledger"}
How can I change the code so that the schema and everything else displays correctly?