IBM Sterling Transformation Extender

Sterling Transformation Extender

Come for answers, stay for best practices. All we're missing is you.

 View Only
  • 1.  Escape all the json forbidden characters in ITX

    Posted Tue November 21, 2023 05:55 PM
    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
    ------------------------------


  • 2.  RE: Escape all the json forbidden characters in ITX

    Posted Fri November 24, 2023 09:30 AM

    Hi Team,

    Can someone help me on this?



    ------------------------------
    Jayachandra M
    ------------------------------



  • 3.  RE: Escape all the json forbidden characters in ITX

    Posted Mon November 27, 2023 03:30 PM

    Can you explain a little more on what you are trying to do? Are you running into issues while reading in (validating and parsing) JSON data, or are you creating invalid output? Are you importing a template or a schema or are you using native JSON support? Design Studio or Design Server?

    best,

    -steph



    ------------------------------
    Stephanie Fetzer
    ------------------------------



  • 4.  RE: Escape all the json forbidden characters in ITX

    Posted Mon November 27, 2023 06:28 PM

    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
    ------------------------------



  • 5.  RE: Escape all the json forbidden characters in ITX

    Posted Tue November 28, 2023 08:12 AM

    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.



    ------------------------------
    Stephanie Fetzer
    ------------------------------