json 转对象函数_JSON_QUERY()函数从JSON数据提取对象

json 转对象函数

In this article, we will explore JSON_QUERY() functions in SQL Server to extract JSON objects and array from the JSON Data.

在本文中,我们将探索SQL Server中的JSON_QUERY()函数,以从JSON数据中提取JSON对象和数组。

JSON概述 (Overview of JSON)

JavaScript Object Notation (JSON) is an accessible format for representing data in a structured way. It consists of lightweight data for data exchange. If you are familiar with Amazon Web Service, DynamoDB, MongoDB, Couchbase databases, you should be familiar with the JSON documents. These NoSQL databases primarily uses JSON structured data. It becomes necessary for SQL database administrators as well to understand JSON and use SQL Server function in conjunction with JSON.

JavaScript Object Notation(JSON)是一种可访问的格式,用于以结构化方式表示数据。 它包含用于数据交换的轻量级数据。 如果您熟悉Amazon Web Service,DynamoDB,MongoDB,Couchbase数据库,则应该熟悉JSON文档。 这些NoSQL数据库主要使用JSON结构化数据。 SQL数据库管理员也必须了解JSON并结合使用SQL Server功能和JSON。

  • It consists of key-value pairs.

    它由键值对组成。
  • SQL Server JSON functions: a bridge between NoSQL and relational worlds for more details SQL Server JSON函数:NoSQL与关系世界之间的桥梁以获取更多详细信息
  • Each key should be enclosed in a double-quote

    每个密钥都应放在双引号中
  • We can have a string, object, array, Boolean or number data format in a value

    我们可以在值中使用字符串,对象,数组,布尔值或数字数据格式
  • Each key should use colon (:) to segregate from the values. For example “Name”:”Rajendra”

    每个键都应使用冒号(:)与值分开。 例如“名称”:“ Rajendra”

Before we go further, I will give a small overview of JSON object and array.

在继续之前,我将简要介绍JSON对象和数组。

  • JSON Object:

    JSON对象:

    In JSON, each object is enclosed by curly brackets({}). In the below example, we have a key (Name), and its value is a JSON object (nested JSON)

    在JSON中,每个对象都用大括号({})括起来。 在下面的示例中,我们有一个键(名称),其值是JSON对象(嵌套JSON)

    "Name" : {
            "FirstName" : "Rajendra"
        }
    

  • JSON Array

    JSON数组

    It is an ordered list of values to store multiple values. We use square brackets to represent an array in the JSON Data. In the following example, we have an employee array that has employees’ records.

    它是值的有序列表,用于存储多个值。 我们使用方括号表示JSON数据中的数组。 在下面的示例中,我们有一个雇员数组,其中包含雇员的记录。

    {   "employees":[      {
                "name":"Raj",
                "email":"[email protected]",
                "age":32
             
       },
             {
                "name":"Mohan",
                "email":"[email protected]",
                "age":21
             
       }
          
       ]
       
        }
    

SQL Server provides the following JSON functions to work with JSON Data:

SQL Server提供以下JSON函数以使用JSON数据:

  • ISJSON(): we can check valid JSON using this function ISJSON():我们可以使用此函数检查有效的JSON
  • JSON_VALUE(): It extracts a scalar value from the JSON data JSON_VALUE():从JSON数据中提取标量值
  • JSON_MODIFY(): It modifies values in the JSON Data. You should go through JSON_MODIFY():修改JSON数据中的值。 您应该Modifying JSON data using JSON_MODIFY() in SQL Server for this function 在SQL Server中使用JSON_MODIFY()来完成JSON数据的修改
  • JSON_QUERY: It extracts an array or string from JSON in SQL Server JSON_QUERY:它从SQL Server中的JSON中提取数组或字符串

We can view these functions in the following image of Microsoft docs.

我们可以在下面的Microsoft docs图像中查看这些功能。

Overview of built-in JSON support

We explored JSON_VALUE() and JSON_MODIFY() functions in my previous articles. You can refer to JSON for these articles. In this article, we are exploring JSON_QUERY() function using various examples.

在之前的文章中,我们探讨了JSON_VALUE()和JSON_MODIFY()函数。 您可以参考JSON以获得这些文章。 在本文中,我们将使用各种示例来探索JSON_QUERY()函数。

JSON_QUERY()的语法 (Syntax of JSON_QUERY())

JSON_QUERY (expression ,[Path Mode] JSON_path)

JSON_QUERY(表达式,[路径模式] JSON_path)

  • Expression: It is a JSON string or a variable holding JSON data 表达式
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值