How to add escape character in derived column and while reading json with just one escape character?

Rajendran, Prakash 1 Reputation point
2021-12-15T14:48:57.48+00:00

This is my expression in derived column:
concat("\/Date(",toString(toLong(toLong(toTimestamp(concat(toString({SOWING FEMALE}, 'yyyy-MM-dd'), " 00:00:00") ,'yyyy-MM-dd HH:mm:ss')-toTimestamp('1970-01-01 00:00:00.000','yyyy-MM-dd HH:mm:ss.SSS'))/1000l)), '000+0200)\/')

My expected output is "/Date(1631577600000+0200)/"

but when I store data in as json format, it gets stored into "\/Date(1631577600000+0200)\/". How can I keep just one escape character?

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,624 questions
0 comments No comments
{count} votes

7 answers

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2021-12-15T15:15:27.313+00:00

    The data is correct. JSON uses '\' as an escape character. Therefore if you want a single '\' in the final data you have to put '\' in the JSON. Otherwise when the data is read out of the JSON it comes back wrong. This is identical to how C++ and C# work with their string literals.

    So, "\/Date" will be read out of the JSON as \/Date. But "/Date" would either produce an error or potentially just be Date, depending upon the parser.


  2. Rajendran, Prakash 1 Reputation point
    2021-12-15T16:09:26.767+00:00

    yes actually I do not want to add escape character but what happened was my initial input looked like this "/Date(1631577600000+0200)/". This then I pass to API. JSON reader automatically converts this into UTC format before calling API. That's when I thought to use escape character but no luck.


  3. Rajendran, Prakash 1 Reputation point
    2021-12-15T17:09:21.06+00:00

    I agree with all your points. I have already put those questions to my team. Just like mentioned in the article ,same here that API is out of control as it is maintained by the client. So I have to check with them. I will also see if the article can give me an work around. Thank you very much @Michael Taylor . I will post the update.

    0 comments No comments

  4. Rajendran, Prakash 1 Reputation point
    2021-12-16T16:07:45.083+00:00

    Yes.. Like I mentioned I thought adding an escape character would solve this issue but unfortunately not and hence the title of this post as such. But it's true that JSON is writing towards 3rd party API. My oringal logic as below

    concat("/Date(",toString(toLong(toLong(toTimestamp(concat(toString({date_column}, 'yyyy-MM-dd'), " 00:00:00") ,'yyyy-MM-dd HH:mm:ss')-toTimestamp('1970-01-01 00:00:00.000','yyyy-MM-dd HH:mm:ss.SSS'))/1000l)), '000+0200)/')


  5. Rajendran, Prakash 1 Reputation point
    2021-12-16T16:50:35.757+00:00

    The below screenshots tell you the flow. I use look up to call the json files and send each row into for each loop which has web activity.

    158276-web-activity.png158287-api-call.png


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.