<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>json &amp;mdash; Attach to Process</title>
    <link>https://devblog.dinobansigan.com/tag:json</link>
    <description>Thoughts and Notes on Software Development</description>
    <pubDate>Tue, 14 Apr 2026 18:20:16 +0000</pubDate>
    <image>
      <url>https://i.snap.as/4wmUdb6N.png</url>
      <title>json &amp;mdash; Attach to Process</title>
      <link>https://devblog.dinobansigan.com/tag:json</link>
    </image>
    <item>
      <title>Querying JSON Array in SQL Server</title>
      <link>https://devblog.dinobansigan.com/querying-json-array-in-sql-server?pk_campaign=rss-feed</link>
      <description>&lt;![CDATA[One of the best additions to SQL Server 2016 is native support for JSON. There a number of articles already covering how to query JSON in SQL Server, so I won&#39;t cover those. What particularly gives me headaches though is querying a JSON Array in SQL Server. Hopefully the scripts below can help someone else. &#xA;&#xA;The SELECT script below can be used when you are working with a very basic JSON array that doesn&#39;t even have a Property for the array. In this example, we have an array of OrderIds.&#xA;DECLARE @OrderIdsAsJSON VARCHAR(MAX) = &#39;[&#34;1&#34;, &#34;2&#34;, &#34;3&#34;]&#39;;&#xA;&#xA;SELECT [value] AS OrderId&#xA;FROM OPENJSON(@OrderIdsAsJSON)&#xA;WITH&#xA;(&#xA;       [value] BIGINT &#39;$&#39;&#xA;);&#xA;&#xA;The second SELECT script below can be used when you are working with a JSON array that does have a Property defined for the array. In this example, we have an array of OrderIds with a defined OrderId property.&#xA;DECLARE @OrderIdsAsJSON VARCHAR(MAX) = &#39;{&#34;OrderId&#34;:[&#34;4&#34;, &#34;5&#34;, &#34;6&#34;]}&#39;;&#xA;&#xA;SELECT [value] AS OrderId&#xA;FROM OPENJSON(@OrderIdsAsJSON, &#39;$.OrderId&#39;)&#xA;WITH&#xA;(&#xA;       [value] BIGINT &#39;$&#39;&#xA;);&#xA;hr /&#xA;&#xA;h4Update: 2019-07-17/h4&#xA;&#xA;Adding another example for a JSON array that came from an Int list in C#. This is how you could query it in SQL Server.&#xA;DECLARE @OrderIds VARCHAR(MAX) = &#39;{&#34;$type&#34;:&#34;System.Int64[], mscorlib&#34;,&#34;$values&#34;:[4, 5, 7, 999]}&#39;;&#xA;&#xA;SELECT [value] AS OrderId&#xA;FROM OPENJSON(@OrderIds, &#39;$.&#34;$values&#34;&#39;);&#xA;&#xA;#SqlServer #Scripts #Database #JSON&#xA;&#xA;a href=&#34;https://remark.as/p/devblog.dinobansigan.com/querying-json-array-in-sql-server&#34;Discuss.../a or leave a comment below.]]&gt;</description>
      <content:encoded><![CDATA[<p>One of the best additions to SQL Server 2016 is <a href="https://docs.microsoft.com/en-us/sql/relational-databases/json/json-data-sql-server?view=sql-server-2017">native support for JSON</a>. There a number of articles already covering how to query JSON in SQL Server, so I won&#39;t cover those. What particularly gives me headaches though is querying a JSON Array in SQL Server. Hopefully the scripts below can help someone else.</p>

<p>The SELECT script below can be used when you are working with a very basic JSON array that doesn&#39;t even have a Property for the array. In this example, we have an array of OrderIds.</p>

<pre><code class="language-sql">DECLARE @OrderIdsAsJSON VARCHAR(MAX) = &#39;[&#34;1&#34;, &#34;2&#34;, &#34;3&#34;]&#39;;

SELECT [value] AS OrderId
FROM OPENJSON(@OrderIdsAsJSON)
WITH
(
       [value] BIGINT &#39;$&#39;
);
</code></pre>

<p>The second SELECT script below can be used when you are working with a JSON array that does have a Property defined for the array. In this example, we have an array of OrderIds with a defined OrderId property.</p>

<pre><code class="language-sql">DECLARE @OrderIdsAsJSON VARCHAR(MAX) = &#39;{&#34;OrderId&#34;:[&#34;4&#34;, &#34;5&#34;, &#34;6&#34;]}&#39;;

SELECT [value] AS OrderId
FROM OPENJSON(@OrderIdsAsJSON, &#39;$.OrderId&#39;)
WITH
(
       [value] BIGINT &#39;$&#39;
);
</code></pre>

<hr/>

<p><em><h4>Update: 2019-07-17</h4></em></p>

<p>Adding another example for a JSON array that came from an Int list in C#. This is how you could query it in SQL Server.</p>

<pre><code class="language-sql">DECLARE @OrderIds VARCHAR(MAX) = &#39;{&#34;$type&#34;:&#34;System.Int64[], mscorlib&#34;,&#34;$values&#34;:[4, 5, 7, 999]}&#39;;

SELECT [value] AS OrderId
FROM OPENJSON(@OrderIds, &#39;$.&#34;$values&#34;&#39;);
</code></pre>

<p><a href="https://devblog.dinobansigan.com/tag:SqlServer" class="hashtag"><span>#</span><span class="p-category">SqlServer</span></a> <a href="https://devblog.dinobansigan.com/tag:Scripts" class="hashtag"><span>#</span><span class="p-category">Scripts</span></a> <a href="https://devblog.dinobansigan.com/tag:Database" class="hashtag"><span>#</span><span class="p-category">Database</span></a> <a href="https://devblog.dinobansigan.com/tag:JSON" class="hashtag"><span>#</span><span class="p-category">JSON</span></a></p>

<p><strong><a href="https://remark.as/p/devblog.dinobansigan.com/querying-json-array-in-sql-server">Discuss...</a></strong> or leave a comment below.</p>
]]></content:encoded>
      <guid>https://devblog.dinobansigan.com/querying-json-array-in-sql-server</guid>
      <pubDate>Thu, 24 Jan 2019 00:00:00 +0000</pubDate>
    </item>
  </channel>
</rss>