Skip to content

API Proposal: SqlJson class design to support JSON datatype #2665

@apoorvdeshmukh

Description

@apoorvdeshmukh

Background:
As part of enhancing support in SqlClient for JSON datatype for Sql Server as mentioned in #2622, SqlDbType needed to be enhanced with enum called Json and introduction of a SqlType class for JSON type was needed.
An enum called Json with value 35 in SqlDbType was recently added in the runtime repo through issue #103925
The next follow up item is to provide a SqlType class to work with the JSON data. This proposal talks about the design of SqlJson class which aims to represent the JSON data stored in or retrieved from a server.

API Proposal

using System;
using System.Data.SqlTypes;
using System.Text.Json;

namespace Microsoft.Data.SqlTypes
{
    /// <summary>
    /// Represents the Json Data type in SQL Server.
    /// </summary>
    public class SqlJson : INullable
    {
        /// <summary>
        /// Parameterless constructor. Initializes a new instance of the SqlJson class which 
        /// represents a null JSON value.
        /// </summary>
        public SqlJson() { }

        /// <summary>
        /// Takes a <see cref="string"/> as input and initializes a new instance of the SqlJson class.
        /// </summary>
        /// <param name="jsonString"></param>
        public SqlJson(string jsonString) { }

        /// <summary>
        /// Takes a <see cref="JsonDocument"/> as input and initializes a new instance of the SqlJson class.
        /// </summary>
        /// <param name="jsonDoc"></param>
        public SqlJson(JsonDocument jsonDoc) { }


        /// <inheritdoc/>
        public bool IsNull => throw null;

        /// <summary>
        /// Represents a null instance of the <see cref="SqlJson"/> type.
        /// </summary>
        public static SqlJson Null { get { throw null; } }

        /// <summary>
        /// Gets the string representation of the Json content of this <see cref="SqlJson" /> instance.
        /// </summary>
        public string Value { get ; }
    }
}

Additionally, SqlDataReader will be enhanced with addition of API for returning SqlJson type

        /// <summary>
        /// Gets the value of the specified column as JSON value.
        /// </summary>
        virtual public SqlJson GetSqlJson(int i)

Metadata

Metadata

Labels

Area\JsonUse this for issues that are targeted for the Json feature in the driver.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions