Categories: DatabasesNews

No Scalars with JSON_QUERY–#SQLNewBlogger from Blog Posts – SQLServerCentral

1 min read

Another post for me that is simple and hopefully serves as an example for people trying to get blogging as #SQLNewBloggers.

I started to dig into JSON queries recently, and as I continued to experiment with JSON, this struck me as strange. Why is there a NULL in the result?

The path looks right. This appears to be somewhere I ought to get a result back. As I looked up the JSON_QUERY documentation, and it says I get an object or array back. I’d somewhat expect that position, while containing a single value, could be seen as an object of

{“setter”}

The fact that I need to know I have a single value here seems like poor design. If the document changes, perhaps someone might enter this:

DECLARE @json NVARCHAR(1000)
     = N'
  {  "player": {
              "name" : "Sarah",
              "position" : "setter, DS"
             },
    "team":"varsity"
  }
';

In this case, a JSON_VALUE would fail, while a JSON_QUERY wouldn’t work in the first example above. This means that I need to modify my code based on documents.

I don’t like this, but I need to know this, so if you work with JSON, make sure you know how the functions work.

SQLNewBlogger

While writing the previous post, I changed one of the function calls and got the NULL. I had to fix things for the other post, but I kept the query and then spent about 10 minutes writing this one to show a little thought into the language.

You can easily take something you are confused about, made a mistake doing, or wonder about and write your own post.

The post No Scalars with JSON_QUERY–#SQLNewBlogger appeared first on SQLServerCentral.

Share
Published by

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago