0

Here is a little snippet of my json text which is in a column in a database. I want to write a query that will return a Boolean value if the values for "1", "2", etc. = 0. So if "1": 0 I want to have a false value so then I can write a conditional statement to display a message depending of the Boolean value.

 {
     "ENABLE": [
        {
            "1": 1,
            "2": 1,
            "3": 1,
            "4": 1
       }
   ]
    }
2
  • 1
    you need to tag your dbms Commented Jul 28, 2021 at 19:04
  • gotcha just updated @eshirvana Commented Jul 28, 2021 at 19:14

1 Answer 1

1

here is one way using jsonb functions:

select jsonb_array_elements((jsonb_extract_path(jsoncolumn::jsonb,'ENABLE'))) @> '{"4":1}'::jsonb as checking
from test 

'{"4":1}' can be parameterized, as if you make a procedure , or if you build your query as dynamic sql.

db<>fiddle here

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.