Skip to content

Sql Server FOR JSON support #317

Open

Description

@JocaPC

Sql Server CTP2 enables developers to format Sql query result set as JSON text (see https://msdn.microsoft.com/en-us/library/dn921882.aspx). We just need to add FOR JSON clause after any query, e.g.:

SELECT *
FROM tab1
WHERE col1 = 4
ORDER BY col2
FOR JSON PATH

Are there some plans to add support for this clause in tedious? In this case we don't need to read rows/cells from result - we can just take entire JSON result object.
Some implementation details:

  1. FOR JSON result set will have exactly one column with name "JSON_F52E2B61-18A1-11d1-B105-00805F49916B". The name of that column will be same in every FOR JSON query.
  2. JSON is not returned as a single cell because we might have big text. Generated JSON text will be split into 2-4K chunks and returned as set of rows with a single column (see Output of the FOR JSON clause in https://msdn.microsoft.com/en-us/library/dn921882.aspx ). Therefore, cells should be concatenated before they are returned as JSON object.

I have tried to execute FOR JSON query with tedious and it works fine; however, I need to concatenate all chunks as a single text in on-row event handler.
It is not a big problem; however, it would be nice to have built-in function/event handler that returns all concatenated chunks as a single JSON object. Maybe to have new event (e.g. on("json", function(json) { ... } ) ) where event handler function will have concatenated chunks as a valid JSON object.
Since it already works fine it seems to me that this concatenation of results could be just a little enhancement that adds a full support.

Activity

  1. spanditcaa commented on May 6, 2016

    @spanditcaa
    Member

    Since it seems to be a popular platform for tedious users, just wanted to note that FOR JSON is available in SQL Azure as well. https://azure.microsoft.com/en-us/blog/json-functionalities-in-azure-sql-database-public-preview/

    Built in handling for tedious would be a great addition.

  2. JocaPC commented on May 6, 2016

    @JocaPC
    Author
  3. patriksimek commented on May 6, 2016

    @patriksimek
    Collaborator

    JSON support was limited to Tedious due to experimental phase. I was curious about the feedback on the implementation. All the logic behind this lays in node-mssql so I added support for additional drivers in 3.3.0.

  4. manu-st commented on Jan 26, 2017

    @manu-st

    Any update on the JSON support from SQL Server 2016?

  5. jovanpop-msft commented on Mar 11, 2017

    @jovanpop-msft

    In SQL Server GitHub samples you can find example RESP API that has some wrapper around tediuos that leverages FOR JSON: https://github.com/Microsoft/sql-server-samples/tree/master/samples/features/json/todo-app/nodejs-express4-rest-api The biggest missing piece is a function that streams results from sql query into some output stream. In this sample is added wrapper function on top of tedious that gets results from Request and on each 'row' event push part of the received JSON into the output stream.
    FOR JSON in SQL Server splits output JSON into 2KB chunks so this is ideal case for output stream. I think that one function that will natively stream chunks from request into stream would be the core feature in REST API implementation, especially in Azure.

  6. added
    Follow up
    on Dec 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Follow upfeature-request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions