How to avoid special character from RETS using phrets?

250 views Asked by At

Is there any mechanism to avoid junk/special character from RETS server using DMQL queries and phrets?

for eg: Avoid enclosed double quotes ("value") from the data. Also avoiding character combination like ("value/"), this is causing lots of issues too.

I can escape once downloaded using php script. But then question is, any direct method that handle such escape from RETS end itself?

Thanks

1

There are 1 answers

3
GantTheWanderer On

Theres nothing I can find in the specification that escapes or ignores characters for you. This feature is beyond the scope of RETS.

The real question being asked here is how to encode JSON in CSV format.

Here is the string you want to encode

"one","two"

say its stored in the start variable

Let encode it as a JSON object:

jsonString = '{"data":"' + start.Replace('"','\\"') + '"}';

-> {"data":"\"one\",\"two\""}

Test it at jsonlint.com and observe its valid JSON

So if you needed to store this in a CSV file, then you have to encode it again.

string csvJsonString = '"' + jsonString.Replace('"','""') + '"';

-> "{""data"":""\""one\"",\""two\""""}"

string validCsv = csvJsonString + "," + csvJsonString

-> "{""data"":""\""one\"",\""two\""""}","{""data"":""\""one\"",\""two\""""}"

Test this at csvlint.io and see that its valid CSV.

At this point the string validCsv is not valid JSON any more of course, it must be parsed by a CSV reader back into JSON.