I'm running below query and taking the values in the variable -
FOR EACH ttTableRecords BREAK BY ttTableRecords.field_recid :
ASSIGN lcFieldValue = lcFieldValue + ttTableRecords.field_value.
ASSIGN lcFieldValue = lcFieldValue + ",".
END.
However output is coming in below format -
lcfieldValue = "20yr,20 Year Membership,MARCUS,MARCUS,HO,DVLP,,"
Thanks,
Krishna Kumar
I want output should come in below format -
lcfieldValue = "20yr","20 Year Membership","MARCUS","MARCUS","HO", "DVLP"
You're only adding comma's to the output. If you want quotes you have to add them
ASSIGN lcFieldValue = lcFieldValue + '"' + ttTableRecords.field_value + '"'.
You could also just change this line:
ASSIGN lcFieldValue = lcFieldValue + ttTableRecords.field_value.
To this:
ASSIGN lcFieldValue = lcFieldValue + QUOTER(ttTableRecords.field_value).
I TRIED. however OUTPUT IS COMING LIKE THIS - Why "/" is coming in output -
"\"20yr\",\"20 Year Membership\",\"MARCUS\",\"MARCUS\",\"HO\",\"DVLP\",\"\",\"\""
I tried. However output is coming in below format . Please let me know why "/" is coming
"\"20yr\",\"20 Year Membership\",\"MARCUS\",\"MARCUS\",\"HO\",\"DVLP\",\"\",\"\""
Thanks,
Krishna
It looks like it is being escaped - that is usually what the \ is for.
How are you writing your output?
Is lcFieldValue a LONGCHAR?
Any reason why you didn't opt for using EXPORT DELIMITER "," ttTableRecords. ? That will help if you need to go directly to file and will dump quotes around string values.
Well, you re using the quoter function. The \" is the escape code for double quotes with a double quoted string.
Hi Mark,
Here is the exact problem.
We are writing a rest API and storing the data in temp-table. Then we are using PDS-OE to map and output the same in JSON Format. Below is the JSON output which we are getting after using -
ASSIGN lcFieldValue = lcFieldValue + QUOTER(ttTableRecords.field_value).
JSON FILE Output
-------------------------
{
"response": {
"data": {
"data": [
{
"Table_recid": 27137,
"columnData": "\"20yr\",\"20 Year Membership\",\"MARCUS\",\"MARCUS\",\"HO\",\"DVLP\",\"\",\"\""
},
{
"Table_recid": 27138,
"columnData": "\"ANFH\",\"\",\"\",\"\",\"\",\"\",\"\",\"Penthouse\""
},
{
"Table_recid": 27139,
"columnData": "\"Anfi preffered\",\"ANFP\",\"\",\"\",\"\",\"\",\"\",\"\""
},
{
"Table_recid": 27140,
"columnData": "\"\",\"\",\"\",\"\",\"Anfi Regular\",\"ANFR\",\"\",\"\""
},
{
Thanks,
Krishna Kumar
Don't know why quoter was suggested, just remove it.
ASSIGN lcFieldValue = lcFieldValue + "," + ttTableRecords.field_value.
at the end:
assign lcFieldValue = trim(lcFieldValue, ",").
to get rid of the leading comma.
Hi Bronco,
I tried with your approach. However output is coming like this -
"response": {
"data": {
"data": [
{
"Table_recid": 27137,
"columnData": "20yr,,20 Year Membership,,MARCUS,,MARCUS,,HO,,DVLP"
},
{
"Table_recid": 27138,
"columnData": "ANFH,,Penthouse"
},
{
"Table_recid": 27139,
"columnData": "Anfi preffered,,ANFP"
},
{
"Table_recid": 27140,
"columnData": "Anfi Regular,,ANFR"
},
{
I want it to come in below format -
" "20yr", "20 Year Membership" , "MARCUS", "MARCUS","HO", "DVLP"
then the quoter function is OK and so is the output of
"\"20yr\",\"20 Year Membership\",\"MARCUS\",\"MARCUS\",\"HO\",\"DVLP\",\"\",\"\""
because that's how it works when you want to have double quotes within a JSON string.
What you want (last post) is not possible since that would produce invalid JSON.
Aha - well, that changes your approach then...
Since JSON is seeing this as a string you will not be able to have the values inside the value as quoted strings - unless you escape them - which what QUOTER did. You will not be able to do that any other way if you want a double quote. The alternative is to rather use a single quote instead "'20y','','20 Year Membership',..."
Not the best way to represent data I have to admit - a child object would have been a better approach in JSON.
or an array of strings
Hi Bronco,
Thanks for your suggestions. However we want JSON in below form-
"data":[
{
"recId":"0001",
"columnData":[
"a0","b0","c0","d0","e0","a0","b0","c0","d0","e0","v","f"
]
}
Is there any way for the same?
Thanks,
Krishna Kumar
Krishna,
May I be so bold as to suggest that what you are seeing in the JSON results is actually what you want since it is valid JSON and that whatever JSON parser you are (or should be) using to parse this JSON will properly handle the escaped double quotes and return to you the data in the form you want.
Brian
That would be a JSON String Array - as Bronco suggested. Instead of Attempting to build (complex) JSON manually, try using the JSON Object Model Parser from the ABL. Progress.Json.ObjectModel.* classes.
FOR EACH ttTableRecords BREAK BY ttTableRecords.field_recid :
ASSIGN lcFieldValue = lcFieldValue +
QUOTER(ttTableRecords.field_value).
ASSIGN lcFieldValue = lcFieldValue + ",".
END.