Reading JSON Format

Hi,

How I can use an expression to read the below in a mapper to get individual values true or false? I am using as - $DocumentId.startsWith(“EBSPERSON_”)

[

{

"Content_ID":

"EBSPERSON_547229"

}

{

"Content_ID":

"EBSPERSONAD_547229"

}

{

"Content_ID":

"EBSPHONE_547229"

}

]

Below is the actual data and I want to pass the value “EBSPERSON_547229” in the target path.

Use below expression :

jsonPath($, "$_Document_ID[?(value.Content_ID.startsWith('EBSPERSON_'))].Content_ID")

Thanks, @Dheeraj - But it didn’t work :frowning:

I see your JSON is not formatted properly. I would recommend validating the JSON snippet using some external validators
You can also attach your pipeline here and I can look into that

Thanks,
HCM Insert Person Records_2022_06_28.slp (65.9 KB)
@Dheeraj - I have attached the pipeline.

@amit.saroha
I won’t be able to validate your pipeline as it needs accounts to connect to the systems. In scenarios like this, it would be great if you can export the data to a JSON generator snap and work on the expressions it would be a lot simpler and easier to debug.

I am attaching a sample pipeline where I tried to replicate your data and worked on the expression.
Test Expr - Community_2022_06_28.slp (3.6 KB)

@Dheeraj , thanks for your help but the sample data is not like the way I have. I have the below data coming out of mapper -

image

In the another mapper when I use it the below error comes -

I just want the value from this like shown below -

I have uploaded the JSON file as well id someone wants to give it a try.

Mapper1_output0.json (144 Bytes)

@amit.saroha
Hope this helps

jsonPath($, "$[?(value.Document_ID.startsWith('EBSPERSON_'))].Document_ID")

The idea is to use the filter operator. It will select all the element/s in the Array that match the given expression. In the above example, my filter condition is based on the value of ‘Document_ID’

2 Likes

@Dheeraj - Thank you for all the help but I am still facing the issue. I think it’s not JSON in Document_ID but it is string (see screenshot # 2). Could you suggest how to overcome it?


h

@amit.saroha
Would you be able to download and share the preview of the upstream snap connected to the mapper snap(labeled
‘Person File’) shared in the screenshot above

Thank you, @Dheeraj for your help.

I have uploaded the output of the previous 3 snaps.

image

Mapper1_output0 (1).json (144 Bytes)
JSON_Splitter output0.json (1.3 KB)
Call_getIntegrationContentId output0.json (3.4 KB)

Thanks, Amit

If i understand your requirement, you are trying to get the highlighted section from the below API response

So, your output from the mapper should be ‘EBSPERSON_550542’ right ?

@Dheeraj - Yes, this is exactly what I am looking for.

@amit.saroha
I have copied the JSON Splitter to a JSON Generator snap and the following expressions works fine in a mapper

jsonPath($, "$[?(value['ns0:IntegrationName']=='EBSPERSON')]['ns0:ContentId']")

Also, attaching the pipeline just in case you need it for reference
Test Expr - Community_2022_06_29.slp (4.9 KB)

@Dheeraj , Thanks again for your help but it does not seems working when I placed the same expression in the mapper for me.

“error”:

“Invalid·JSON-path:·$[?(value[‘ns0:IntegrationName’]==‘EBSPERSON’)][‘ns0:ContentId’]”

“stacktrace”:

“com.snaplogic.common.jsonpath.InvalidPathException:·Invalid·accessor·(http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/)·in·path:·com.snaplogic.snap.api.ExpressionLocation@708cedde\r\n—at·com.snaplogic.expression.JsonPathExpressionService.evaluate(JsonPathExpressionService.java:119)\r\n—at·com.snaplogic.jsonpath.PathWalker.evaluate(PathWalker.java:167)\r\n—at·com.snaplogic.jsonpath.tokens.FilterToken.testMember(FilterToken.java:57)\r\n—at·com.snaplogic.jsonpath.tokens.FilterToken.traverse(FilterToken.java:71)\r\n—at·com.snaplogic.jsonpath.tokens.SubscriptToken.traverse(SubscriptToken.java:51)\r\n—at·com.snaplogic.jsonpath.PathWalker.traverse(PathWalker.java:402)\r\n—at·com.snaplogic.jsonpath.PathWalker.traverse(PathWalker.java:462)\r\n—at·com.snaplogic.jsonpath.JsonPathImpl.read(JsonPathImpl.java:138)\r\n—at·sl.EvaluatorUtils.jsonPathRead(EvaluatorUtils.java:697)\r\n—at·com.snaplogic.expression.GlobalScope$JsonPathFunction.eval(GlobalScope.java:302)\r\n—at·sl.EvaluatorUtils.callFunction(EvaluatorUtils.java:760)\r\n—at·SC.evaluate(Unknown·Source)\r\n—at·com.snaplogic.util.ExpressionUtils$MyExpressionProperty.eval(ExpressionUtils.java:281)\r\n—at·com.snaplogic.snap.api.impl.PropertyValuesImpl$ValidatingExpressionProperty.eval(PropertyValuesImpl.java:1005)\r\n—at·com.snaplogic.snaps.transform.DataTransform.processBinary(DataTransform.java:263)\r\n—at·com.snaplogic.snaps.transform.DataTransform.process(DataTransform.java:216)\r\n—at·com.snaplogic.snap.api.ExecutionUtil.process(ExecutionUtil.java:106)\r\n—at·com.snaplogic.snap.api.ExecutionUtil.executeForDocument(ExecutionUtil.java:118)\r\n—at·com.snaplogic.snap.api.ExecutionUtil.execute(ExecutionUtil.java:81)\r\n—at·com.snaplogic.snap.api.SimpleSnap.execute(SimpleSnap.java:70)\r\n—at·com.snaplogic.cc.snap.common.SnapRunnableImpl.executeSnap(SnapRunnableImpl.java:800)\r\n—at·com.snaplogic.cc.snap.common.SnapRunnableImpl.executeForSuggest(SnapRunnableImpl.java:647)\r\n—at·com.snaplogic.cc.snap.common.SnapRunnableImpl.doRun(SnapRunnableImpl.java:856)\r\n—at·com.snaplogic.cc.snap.common.SnapRunnableImpl.call(SnapRunnableImpl.java:435)\r\n—at·com.snaplogic.cc.snap.common.SnapRunnableImpl.call(SnapRunnableImpl.java:117)\r\n—at·java.base/java.util.concurrent.FutureTask.run(Unknown·Source)\r\n—at·java.base/java.util.concurrent.Executors$RunnableAdapter.call(Unknown·Source)\r\n—at·java.base/java.util.concurrent.FutureTask.run(Unknown·Source)\r\n—at·java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown·Source)\r\n—at·java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown·Source)\r\n—at·java.base/java.lang.Thread.run(Unknown·Source)\r\nCaused·by:·com.snaplogic.snap.api.SnapDataException:·Invalid·accessor·(http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/)·in·path:·com.snaplogic.snap.api.ExpressionLocation@708cedde\r\n—at·sl.EvaluatorUtils.indexSuffix(EvaluatorUtils.java:1411)\r\n—at·SC.evaluate(Unknown·Source)\r\n—at·com.snaplogic.expression.JsonPathExpressionService.evaluate(JsonPathExpressionService.java:117)\r\n—…·30·more\r\n”

“reason”:

“Invalid·accessor·(http://xmlns.oracle.com/apps/hcm/processFlows/core/flowActionsService/types/)·in·path:·com.snaplogic.snap.api.ExpressionLocation@708cedde”

“resolution”:

“Please·check·expression·syntax·and·data·types.”

“status_code”:

“error”

Per my understanding, you need to get the fields out of objects in array, that their value starts with “EBSPERSON_”. If that’s so, try the following expression:

$Document_ID.map(x=>x.filter((v,k)=> v.startsWith('EBSPERSONAD_')))

1 Like