title: Convert JSON into BigQuery STRUCT
body: <p>I have a JS UDF function which takes a bigquery struct (as json) iterates through properties and transforms the data. Here is the code:</p>
  <pre><code>CREATE TEMP FUNCTION transform_STRUCT_values(events STRING)
      RETURNS STRING
      LANGUAGE js AS
      &quot;&quot;&quot;
        if (!events)
          return null
      
        obj = JSON.parse(events)
        res = {}
        
        for (const prop in obj) {
          // process
        }
      
        return JSON.stringify(res)
      &quot;&quot;&quot;;
      
  SELECT transform_STRUCT_values(TO_JSON_STRING(events)) FROM foo
  </code></pre>
  <p>Now when the result gets back to BigQuery its JSON. Is there any way to convert it into STRUCT again. For example:
  I feed the function with a struct object</p>
  <pre><code>&lt; events.clicks: 14,
  events.closed: 24,
  events.reopened: 31,
  ... many more keys here
  &gt;
  </code></pre>
  <p>Now I want to, say add 1 to each values, the easiest way to do this is JS UDF right?
  I want to make this struct as follows:</p>
  <pre><code>&lt; events.clicks: 15,
  events.closed: 25,
  events.reopened: 32,
  ... many more keys here
  &gt;
  </code></pre>
  <p>But through the UDF I can get this as a JSON object. To convert this into struct again, I have to use:</p>
  <pre><code>JSON_EXTRACT_SCALAR(events, '$.clicks)
  JSON_EXTRACT_SCALAR(events, '$.closed)
  JSON_EXTRACT_SCALAR(events, '$.reopened)
  etc..
  </code></pre>
  <p>NOTE: The events struct is too big so I cannot use <strong>JSON_EXTRACT_SCALAR</strong> for all keys.</p>
  <p>I couldn't find anything like this on the internet so a &quot;its not possible yet&quot; answer could also be accepted. But let's have such question answered for searchers like me)</p>