Personalized Community is here!
Quickly customize your community to find the content you seek.
Check out the latest Business Central updates!Learn about the key capabilities and features of Dynamics 365 Business Central and experience some of the new features.
Overview | Guided Tour | Free Trial
2023 Release Wave 1Check out the latest updates and new features of Dynamics 365 released from April 2023 through September 2023
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Community | FastTrack Program | Finance and Operations TechTalks | Customer Engagement TechTalks | Upcoming TechTalks | All TechTalks
This post starts with me wanting to format some JSON with line breaks for the user to read. It’s the response from an Azure Function which integrates with a local SQL server (interesting subject, maybe for another time). The result from SQL server is serialized into a (potentially very long) JSON string and this is the string that I want to present in a more human-readable format.
If you’re still here then here are the stations that the train of thought pulled into, starting with the worst.
Have some control on my page for the user to view the JSON returned from the Azure Function, formatted with line breaks.
Why not just add the line breaks when I am serializing the results in the C# of my Azure Functions? That way I don’t need to change anything in AL.
No, that’s dumb. That would make every response from the function larger than it needs to be just for the rare occasions when a human might want to read it. Don’t do that.
I could have a second Azure Function to accept the unformatted result and return the formatted version. I could have a Function App which runs node.js and return the result in a couple of lines of code.
The AL code ends up looks like this:
local procedure SetResult(NewResult: Text)
NewResult := NewResult.Replace('''', '');
JS := StrSubstNo('document.write('''' + JSON.stringify(JSON.parse(''%1''), '''', 2) + '''');', NewResult);
'' + JSON.stringify(JSON.parse(''%1''), '''', 2) + ''
If you’re not using 26 single quotes in three lines of code then you’re not doing it right
Business Applications communities