0

I have a column that contains some data like this:

{
  "activity_goal": 200,
  "members": [
    {
      "json": "data"
    },
    {
      "HAHA": "HAHA"
    },
    {
      "HAHA": "HAHA"
    }
  ],
  "name": "Hunters Team v3",
  "total_activity": "0",
  "revenue_goal": 200,
  "total_active_days": "0",
  "total_raised": 300
}

I am using cast(team_data -> 'members' as jsonb) to get the "Members" JSON array, which gives me a column like this:

[
  {
    "json": "data"
  },
  {
    "HAHA": "HAHA"
  },
  {
    "HAHA": "HAHA"
  }
]

I am using array_length(cast(team_data -> 'members' as jsonb), 1) to pull a column with the number of Members that exist in the list. When I do this, I am given this error: function array_length(jsonb, integer) does not exist Note: I have also tried casting as "json" instead of "jsonb"

I am following this documentation. What am I doing wrong?

1 Answer 1

1

Use the JSON functions when working with json such as json_array_length

select json_array_length(team_data -> 'members') from mytable
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.