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

Extracting from Json error

sp41832
New Contributor

Hi,

i have a json error as below

โ€œerrorโ€: โ€œPipeline did not complete successfullyโ€,
โ€œstacktraceโ€: โ€œcom.snaplogic.snap.api.SnapDataException: Pipeline did not complete successfully\n\tat com.snaplogic.snaps.flow.PipeExec$PipeCompletionHandler.run(PipeExec.java:1245)\n\tat com.snaplogic.snaps.flow.PipeExec$2.run(PipeExec.java:728)\n\tat java.lang.Thread.run(Thread.java:748)\nโ€,
โ€œreasonโ€: โ€œSnap errors: {ruuid=ba88d53f-a76b-4557-9da4-469c054f5ba0, reason=Table โ€˜Netsuite.PAYROLL_ITEMSโ€™ doesnโ€™t exist, error code: 1146, SQL state: 42S02, failure=SQL operation failed, label=MySQL - Execute, resolution=Please check for valid Snap properties and input data.}โ€,
โ€œresolutionโ€: โ€œFix the child pipeline errors and try againโ€,
โ€œstatus_codeโ€: โ€œerrorโ€,
โ€œrun_idโ€: โ€œ372fce27-d73b-41e3-9f61-d26b1af4f1c5โ€,
โ€œchild_errorsโ€: [
{
โ€œruuidโ€: โ€œba88d53f-a76b-4557-9da4-469c054f5ba0โ€,
โ€œreasonโ€: โ€œTable โ€˜Netsuite.PAYROLL_ITEMSโ€™ doesnโ€™t exist, error code: 1146, SQL state: 42S02โ€,

Can i extract the highlighted text and put it in a file in my data base.
strong text.

The design is somehting like this, I have a regular pipeline which calls an error pipeline on receiving any error, the error i receive is in Json and i need to have only the error highlighted above, is it Possinle and how?

Thanks in Advance.

4 REPLIES 4

stephenknilans
Contributor

It is certainly possible. There are other ways it could be done, though I have used the regular scripting object to do things like this. You CAN, obviously just pull child_errors.reason, and call it a day.

Steve

Hi Stephen,

Used Json splitter, and given the Json Path* as $[][][0:9]
and the result was
โ€œruuidโ€: โ€œb40505c0-59a0-480b-b4cd-b35633007107โ€,
โ€œreasonโ€: โ€œTable โ€˜Netsuite.PAYROLL_ITEMSโ€™ doesnโ€™t exist, error code: 1146, SQL state: 42S02โ€,
โ€œfailureโ€: โ€œSQL operation failedโ€,
โ€œlabelโ€: โ€œMySQL - Executeโ€,
โ€œresolutionโ€: โ€œPlease check for valid Snap properties and input data.โ€
the link where i verified is โ€œhttp://jsonpath.comโ€, however the snaplogic does not allow this.

Let me know , how can i extract the error

@sp41832

Use below syntax on mapper-

$reason.substring($reason.indexOf(โ€˜{โ€™),$reason.length).split(โ€˜,โ€™)[1].toString()

In the splitter, you can put the base object, like $ child_errors, though as long as you end up with a proper jason object, you can use it.

In a mapper, in this particular case, $reason will be set to: Table โ€˜Netsuite.PAYROLL_ITEMSโ€™ doesnโ€™t exist, error code: 1146, SQL state: 42S02

You are over thinking this as, internally, stuff like this is treated as jason and given special treatment as such. Of course formatting as CSV allows you to treat it that way, etcโ€ฆ AND, if you have this down to one level, you can even have it formatted to CSV.

So a lot of what you are trying to work through is already done.

This is also why supratimโ€™s method will work. If you notice, it starts with the string โ€œ$reasonโ€. The other items, like .substring() are methods you can use on that string to do things like extract a portion of it.