Dynamics 365 Business Central: why not start supporting the JSON data type for table fields?

In the last months I worked on some cloud-based applications that use Azure SQL as backend (details not relevant here) and that use JSON documents extensively. Doing that I’m increasingly inclined to revive an old idea that I had already shared here in the past: why not supporting the JSON data type for table fields also in Dynamics 365 Business Central?

Azure SQL Database supports JSON data type natively from more than 1 year. The JSON type allows you to store JSON documents in a native binary format that is optimized for storage and query performance. Advantages of this new data type are a lot:

  • Optimized for easy querying and manipulation
  • More efficient reads, as the document is already parsed
  • More efficient writes, as the query can update individual values without accessing the entire document
  • More efficient storage, optimized for compression

The json type internally stores data using UTF-8 encoding, Latin1_General_100_BIN2_UTF8 and this behavior matches the JSON specification.

Azure SQL also supports a set of interesting aggregates and operators to natively work with JSON documents in a very performant way.

Just to provide some examples, here is how you can create a table with a field of type JSON:

and here is a T-SQL code that inserts a JSON document into the relative Json field:

Why not having the possibility to do the same in AL? Something like in the following table’s definition:

When you have a field with JSON as data type on SQL, you can easily and quickly retrieve JSON properties using SQL/JSON path expressions. For example, this code retrieves the AccountNumber property of the stored JSON document:

Can you imagine how useful could be this in AL when you have a JSON document stored in a table’s field?

In T-SQL the OPENJSON sentence also permits you to handle JSON documents and perform queries on them. Here is an example:

Other useful Azure SQL features that I love a lot when working with JSON documents are the JSON_OBJECTAGG and JSON_ARRAYAGG aggregates functions, that permits you to construct a JSON object from an aggregation of SQL data or columns.

Here is an example. Imagine to have the following two SQL tables:

and on this table you have the following values:

Now imagine that to interact with an external application (API) you need to have a single JSON document taking data from the two tables. In T-SQL you can do something like the following:

and the result of this query will be a JSON document like the following:

All is native in the platform (very performant!). I can see a lot of interesting usage on this data type and on these aggregators, so imagine to have native AL methods for doing all the operations I’ve described here directly at the SQL level.

Maybe someone can start thinking on that for vNextNext? 🤗 In the meantime, there’s an idea opened here if you want to support:

Original Post https://demiliani.com/2024/11/04/dynamics-365-business-central-why-not-start-supporting-the-json-data-type-for-table-fields/

0 Votes: 0 Upvotes, 0 Downvotes (0 Points)

Leave a reply

Follow
Sign In/Sign Up Sidebar Search
Popular Now
Loading

Signing-in 3 seconds...

Signing-up 3 seconds...