0

I want to insert JSON with the value of the array from postgrsql to value into JSON-type columns. What should I do?

CREATE TABLE jsonlist (col JSON);

INSERT INTO jsonlist(col)
VALUES ('{"usrGrp":"{1,2,3}"}');

1
  • 1
    In JSON arrays are surrounded by square brackets [1,2,3] Commented Feb 7, 2023 at 6:36

1 Answer 1

1

I got it:

'{"action":"del","usrId": ["yjshin","test111"],"usrGrpId": [1,2]}'

You can use brackets to tie up what you want to make a list. Note that in the array, the string had to enclose each element in double quotes, and the entire JSON had to be enclosed in single quotes.

Sign up to request clarification or add additional context in comments.

1 Comment

This doesn't have anything to do with the question. To insert JSON you just need to pack it into a string literal (or pass it as parameter in a prepared statement). It behaves like regular strings, JSON doesn't need any special treatment. You're seemingly asking how to encode arrays in JSON, which is a different thing.

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.