<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: How to extract values from JSON array field? in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/how-to-extract-values-from-json-array-field/m-p/5870#M2143</link>
    <description>&lt;P&gt;For doing a search in a JSON array, one needs to use&amp;nbsp;&lt;/P&gt;&lt;P&gt;OPENJSON&lt;/P&gt;&lt;P&gt;DECLARE @table TABLE (Col NVARCHAR(MAX))&lt;/P&gt;&lt;P&gt;INSERT INTO @table VALUES ('{"names":["Joe","Fred","Sue"]}')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM @table &lt;/P&gt;&lt;P&gt;WHERE 'Joe' IN ( SELECT value FROM OPENJSON(Col,'$.names'))  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or as an alternative, one can use it with&amp;nbsp;&lt;/P&gt;&lt;P&gt;CROSS APPLY&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;SELECT * FROM &lt;/P&gt;&lt;P&gt;    @table &lt;/P&gt;&lt;P&gt;    CROSS APPLY OPENJSON(Col,'$.names')&lt;/P&gt;&lt;P&gt;WHERE value ='Joe'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
    <pubDate>Fri, 14 Apr 2023 07:01:55 GMT</pubDate>
    <dc:creator>Avinash_94</dc:creator>
    <dc:date>2023-04-14T07:01:55Z</dc:date>
    <item>
      <title>How to extract values from JSON array field?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-extract-values-from-json-array-field/m-p/5869#M2142</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;While creating an SQL notebook, I am struggling with extracting some values from a JSON array field. I need to create a view where a field would be an array with values extracted from a field like the one below, specifically I need the `value`  field.&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;[{"sources": [{"providerIds": ["xx"], "source": "vendor", "status": "Verified", "type": "PersonalMobile", "updatedAt": {"$date": 1606563305398}}], "status": "Verified", "type": "PersonalMobile", "updatedAt": {"$date": 1606563305398}, "value": "+1-555-555"}, {"sources": [{"providerIds": ["xx"], "source": "vendor", "status": "Verified", "type": "PersonalMobile"}], "status": "Verified", "type": "PersonalMobile", "updatedAt": {"$date": 1606563305398}, "value": "+1-666-666"}]&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I tried a few things:&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT [*].value from personalPhones&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT from_json(personalPhones:[*].value, 'string')&lt;/CODE&gt;&lt;/PRE&gt;&lt;PRE&gt;&lt;CODE&gt;SELECT from_json(personalPhones:[*], 'value string'&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;It's syntax error OR invalid schema. &lt;/P&gt;&lt;P&gt;Any suggestions?&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 06:54:50 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-extract-values-from-json-array-field/m-p/5869#M2142</guid>
      <dc:creator>vicusbass</dc:creator>
      <dc:date>2023-04-14T06:54:50Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract values from JSON array field?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-extract-values-from-json-array-field/m-p/5870#M2143</link>
      <description>&lt;P&gt;For doing a search in a JSON array, one needs to use&amp;nbsp;&lt;/P&gt;&lt;P&gt;OPENJSON&lt;/P&gt;&lt;P&gt;DECLARE @table TABLE (Col NVARCHAR(MAX))&lt;/P&gt;&lt;P&gt;INSERT INTO @table VALUES ('{"names":["Joe","Fred","Sue"]}')&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;SELECT * FROM @table &lt;/P&gt;&lt;P&gt;WHERE 'Joe' IN ( SELECT value FROM OPENJSON(Col,'$.names'))  &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Or as an alternative, one can use it with&amp;nbsp;&lt;/P&gt;&lt;P&gt;CROSS APPLY&lt;/P&gt;&lt;P&gt;.&lt;/P&gt;&lt;P&gt;SELECT * FROM &lt;/P&gt;&lt;P&gt;    @table &lt;/P&gt;&lt;P&gt;    CROSS APPLY OPENJSON(Col,'$.names')&lt;/P&gt;&lt;P&gt;WHERE value ='Joe'&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 07:01:55 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-extract-values-from-json-array-field/m-p/5870#M2143</guid>
      <dc:creator>Avinash_94</dc:creator>
      <dc:date>2023-04-14T07:01:55Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract values from JSON array field?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-extract-values-from-json-array-field/m-p/5871#M2144</link>
      <description>&lt;P&gt;select *, PersonalPhones:[0].value as Value  from &amp;lt;table_name&amp;gt; &lt;/P&gt;&lt;P&gt;This can give you in the array format&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 07:02:11 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-extract-values-from-json-array-field/m-p/5871#M2144</guid>
      <dc:creator>User16756723392</dc:creator>
      <dc:date>2023-04-14T07:02:11Z</dc:date>
    </item>
    <item>
      <title>Re: How to extract values from JSON array field?</title>
      <link>https://community.databricks.com/t5/data-engineering/how-to-extract-values-from-json-array-field/m-p/5872#M2145</link>
      <description>&lt;P&gt;Maybe I didn't explain it correctly. The JSON snippet from the description is a cell from a row from a table.&lt;/P&gt;</description>
      <pubDate>Fri, 14 Apr 2023 16:26:46 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/how-to-extract-values-from-json-array-field/m-p/5872#M2145</guid>
      <dc:creator>vicusbass</dc:creator>
      <dc:date>2023-04-14T16:26:46Z</dc:date>
    </item>
  </channel>
</rss>

