And Greg I just reminded me - these substitutions happen automatically in ITX if you are using the native JSON support. The substitution posted is only needed if you are using a type tree.
Original Message:
Sent: Mon November 27, 2023 06:28 PM
From: Stephanie Fetzer
Subject: Escape all the json forbidden characters in ITX
Without knowing exactly what you are doing I will take a guess. IF you have a file coming in and you want the list of substitutions you posted to automatically occur, you might want to consider a pre or a post processor map to make whatever the text which has the offensive to JSON chars in and to simply swap them out. You can add a sync output card 1 for a preprocessor. You could add a new last output card for a post processor or you could simply have a stand alone map.
For a stand alone map you could take the input (defined as a blob text item, in this example I will call it blob) and map to the output (defined as a blob text item) and transform the input to the output with a single rule. This could be your rule:
=SUBSTITUTE ( blob,"/","//", "<BS>","/b", "<FF>","/f", "<NL>","/n", "<CR>","/r", "<HT>","/t", """","/"+"""" )
I call this the single shot substitute - in one pass it swaps out each pair between the input and the output.
/ is replaced with //
backspace is replaced with /b
.... and so on....
the only tricky one is the last one - """","/"+""""
which is a double quote replaced with a double quote followed by a /
Hope this helps, if not, post more details on what you are trying to do and I'm sure someone will have suggestions.
-Steph
------------------------------
Stephanie Fetzer
Original Message:
Sent: Tue November 21, 2023 10:09 AM
From: Jayachandra M
Subject: Escape all the json forbidden characters in ITX
I am using ITX to transform and i need to escape all the json forbidden characters.
I thought I could use Item Restrictions (Character/Exclude) to exclude forbidden characters and replace them with the reference string.
json forbidden characters which needs to be escaped:
Backspace to be replaced with \b
Form feed to be replaced with \f
Newline to be replaced with \n
Carriage return to be replaced with \r
Tab to be replaced with \t
Double quote to be replaced with \"
Backslash to be replaced with \\
Any help would be HUGELY appreciated.
------------------------------
Jayachandra M
------------------------------