-3

Say you have a list of json dictionaries in a BigQuery column called "metadata", like so:

  "mentions": [
    {
      "start": 3,
      "end": 17,
      "username": "xyz",
      "id": "12344566"
    },
    {
      "start": 19,
      "end": 34,
      "username": "abc",
      "id": "988649348"
    },
    {
      "start": 35,
      "end": 47,
      "username": "jfk",
      "id": "293489234"
    }
  ]

How can I extract start's values into an array, recursively?:

[3, 19, 35]

Not simply by accessing elements like [0] [1] etc, but recursively

3
  • I've gone ahead and removed the tag spam here; based on the content I've left BigQuery, but if this isn't correct, please edit your question to correctly tag. Why does tagging multiple RDBMS products make my question unclear? Commented May 21 at 13:14
  • 2
    You'd probably need to start with valid JSON. Commented May 21 at 13:16
  • sorry, added valid json and a more helpful example Commented May 21 at 17:41

1 Answer 1

0

Sorry for this stupid question, I found the solution here BigQuery: Extract values of selected keys from an array of json objects

select ARRAY(
  SELECT JSON_EXTRACT_SCALAR(json_array, '$.start') from UNNEST(JSON_EXTRACT_ARRAY(metadata,"$.mentions"))json_array
) as extracted_start
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.