1

I am using json_arrayagg in Oracle to create a json array from multiple rows in a table. Here are details:

create table classInfo (classId integer, category CLOB);
insert into classInfo(1, '{"category":"AAA"}');
insert into classInfo(2, '{"category":"BBB"}');
commit;


select json_arrayagg(category returning clob) from classInfo;

The output has a \ along with " as following:

["{\"category\""AAA\"}", "{\"category\":\"BBB\"}"]

How can I get ride off those \ ?

Thanks in advance!

3
  • What interface are you using to run your query? I don't see the slashes on my system; I suspect they are not added by Oracle database, but by your client interface. Commented Jun 20, 2022 at 20:57
  • 1
    Other than that - when you post data for us for testing (which is a good thing!), please test those statements yourself first, and fix any errors you find. Your INSERT statements are missing the VALUES keyword. That doesn't add to credibility! Commented Jun 20, 2022 at 20:59
  • Does this answer your question? Remove escape characters from JSON_OBJECT output Commented Jun 20, 2022 at 22:06

1 Answer 1

2

Use FORMAT JSON:

select json_arrayagg(category FORMAT JSON RETURNING CLOB) from classInfo;

Which outputs:

JSON_ARRAYAGG(CATEGORYFORMATJSONRETURNINGCLOB)
[{"category":"AAA"},{"category":"BBB"}]

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.