Forum Discussion

Ajay_Chawda's avatar
Ajay_Chawda
Contributor
3 years ago

Write file to US-ASCII file format

Hello Experts ,
I’m trying to write file in US-ASCII file format.

i have used mapper–>binary copy–>transcoder–>file writer snap.

Mapper has input string and binary output. Binary copy snap to make copy of result of mapper.
transcoder snap with setting UTF-8 to US-ANSCII format and then file writer snap to write file.

But transcoder fails with error saying “Failed to transcode from UTF-8 to US-ASCII, reason=The character set in the input data may not be UTF-8,”

above pipeline is getting triggered from parent pipeline which pass input string to this pipeline.

Any suggestion what wrong i’m doing over here?

Regards,
Ajay

4 Replies

  • Charles's avatar
    Charles
    New Contributor II

    Thanks for the reply @bojanvelevski.

    I think the issue may be that expressions are not allowed in the JSON Generator snap? The solution to my problem is easy enough, I’ll just put a mapper snap before my JSON Generator snap and use the “null-safe access” option to fill in the blanks where needed, but I am surprised this isn’t an option in the JSON Generator snap, and I’m also not sure if any expressions are allowed.

    See the very basic chain-JSON Generator pipeline that demonstrates the problem. I can’t reference the input object with an $.get(“num”) expression.

    JSON Generator Expression Test_2021_12_06.slp (4.7 KB)

    • bojanvelevski's avatar
      bojanvelevski
      Valued Contributor

      Didn’t noticed that we are talking about JSON Generator snap. @viktor_n 's suggestion should work.

    • viktor_n's avatar
      viktor_n
      Contributor II

      I’ve tried the same as I showed you in response above, only thing that I’ve changed was that I was using fields that you provided in the post and I couldn’t work them out anyhow.

      I’ve also tried with apache velocity but nothing.

      Problem are those “:” you have in the name. I don’t know why but you can not map fields in JSON Generator with square brackets.

      Solution could be as you said to map the first in mapper and pass it to JSON Generator with null-safe-access, or with expression to remove those “:” from the name of the field.

      • ptaylor's avatar
        ptaylor
        Employee

        @Charles Please note the following documentation at the top of the default template in the JSON Generator:

        Enter your JSON-encoded data in this space. Note that this text is
        treated as an Apache Velocity template, so you can substitute values
        from input documents or the pipeline parameters. See the following
        URL for more information about Velocity:
        https://velocity.apache.org/engine/devel/user-guide.html

        This means you can use Velocity syntax, not SnapLogic EL syntax, in your templates, like this:

        [
            {
                "result" :
        #if($msg)
                ${msg}
        #else
                ${fallback}
        #end
            }
        ]
        

        Here’s a pipeline to demonstrate this:
        Velocity Null Check_2021_12_07.slp (4.8 KB)

        You can do the same on a single line like this:

                "result" : #if($msg) $msg #else $fallback #end