I have postgresql copy command like
\copy (select row_to_json(xyz) from (select employeeJson from employee where empid='1006') xyz) to '/home/users/emp_create_cp_1006.json';
emplyeejson is a jsonb column and having record like
{
"empid": 1006,
"userId":"rirani",
"jobTitleName":"Developer",
"firstName":"Bala",
"lastName":"K",
"preferredFullName":"Bala K",
"employeeCode":"E1",
"region":"CA",
"phoneNumber":"408-1234567",
"emailAddress":"[email protected]",
"address" : "10\" sarah apartment"
}
when the file is generated ,the address value become "10\" sarah apartment" ,which is a invalid json.
employeejsonis a jsonb column, thenrow_to_json(xyz)doesn't really make sense. You are nesting one JSON value into another. It seems you just want:\copy (select employeeJson from employee where empid=1006) to '/home/users/emp_create_cp_1006.json'