cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

Unexpected error with JSON generator

jfpelletier
New Contributor III

Hello!

I'm new to this board and SnapLogic in general, so this should be an easy one to resolve... ๐Ÿ™‚

I'm creating a very simple pipeline where I use a HTTP client to read a list of ongoing, "live" projects tracked on a server, then I need to use that list to create new project shells (projects with no data except the project name) in a different system. I basically replicate projects from one system to another by using only their names.

From the HTTP client response to query the list of projects metadata I use a JSON splitter to get an array of strings for the project names only (jsonPath($, "entity.results[*].name")), then I use a JSON generator to prepare the payload for the next step, which is the creation of new projects on a different system, using the list of project names as input, and the HTTP client to POST the requests.

What I get from the JSON splitter seems valid, here's an example:

 

[
{"splitValue":"Name of the first project"},
{"splitValue":"Name of the second project"},
{"splitValue":"Name of the third project"},
{"splitValue":"Name of the fourth project"}
]

 

This is the JSON that I'm trying to create as payload for the next HTTP client step:

 

{
    "name": "${_splitValue}",
    "customerId": 771373363,
    "templateId": 86723995468
}

 

That doesn't work, here's what I'm getting as response (error message):

 
"error":
"Unexpected character ('"' (code 34)): was expecting comma to separate Object entries\n at [Source: (com.snaplogic.snaps.transform.NamedInputStream); line: 2, column: 16]"
 
Looks like my JSON is wrong, but I can't figure out what I'm doing wrong... Any idea to help me?
 
Thanks in advance!
 
JF
1 ACCEPTED SOLUTION

koryknick
Employee
Employee

I didn't notice before, but you don't want to have anything in the Multipart sub-type property.  Clear that $ from the expression and uncheck the expression enabler.

koryknick_0-1698779666090.png

 

View solution in original post

8 REPLIES 8

koryknick
Employee
Employee

@jfpelletier - Welcome to the Community.  To fix your JSON Generator, I believe you simply need to change how you're referencing the value.  Try this:

{
    "name" : $splitValue,
    "customerId" : 771373363,
    "templateId" : 8672995468
}

 Or you could try using the Mapper snap, which simplifies the construct of these JSON objects since it directly maps the JSON paths in source to target expressions.  The same construct as above is done in a Mapper as follows:

koryknick_0-1698703113630.png

I hope this helps!

 

 

Hello @koryknick,

Thanks a lot for your reply, both options work to give me the correct JSON that I need. ๐Ÿ™‚

I prefer the one with the mapper, it seems simpler to me.

The results in the following snap are not good however, I'm getting a 415 error message from the server to which I'm sending this payload.

If I manually enter value for the payload, it works well, the other system returns a 202 (success).

jfpelletier_0-1698771723956.png

However, if I use the results from the previous snap (the JSON structure that I just generated) as multi-part, I'm getting the 415 error message:

jfpelletier_1-1698772083212.png

The small characters: Failure: class java.util.LinkedHashMap cannot be cast to class java.lang.String (java.util.LinkedHashMap and java.lang.String are in module java.base of loader 'bootstrap'), Reason: Snap failed unexpectedly and did not provide any reason.

I must be doing something very wrong... Can you see why it's not working?

Thanks!

JF

 

koryknick
Employee
Employee

@jfpelletier - it looks like you need to change your Multipart Form "Key" names into static strings by disabling the expression button and removing the $.  So it would look like this:

koryknick_0-1698773048627.png

Hope this helps!

 

Hello @koryknick,

Thanks for your reply!

I'm unfortunately getting the same error, please see screenshot below. I'm also wondering how I can dynamically get the project name if I remove the expression button, isn't it how I can get the field values?

jfpelletier_0-1698778325991.png

Thanks,

JF