cancel
Showing results for 
Search instead for 
Did you mean: 

Reading JSON Format

amit_saroha
New Contributor III

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"

}

]
18 REPLIES 18

amit_saroha
New Contributor III

@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']")

image

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

amit_saroha
New Contributor III

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

image

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

bojanvelevski
Valued Contributor

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_')))