Package: eha-jsonpath
jsonpath-extensionsProvides newExtensions to the jsonpath_ng python libraryto provide commonly requested functions.  The context for these functions is always the value provided from the resolution of the provided jsonpath. The functions will all handle lists or single values as inputs unless explicitly marked. If you're confused about a function's intended, behavior take a look atthe tests.Usagefromeha_jsonpathimportparse# The following is pseudocode, don't copy it.obj={'my':'object'}path='$.some.jsonpath.`fn(arg1, arg2)`'matches=parse(path).find(obj)New ExtensionsCastAttempts to apply a cast to the result of a jsonpath expression.
Will operate invidiually on array items in the case the path resolves to an array.usage:$.my.path.`cast({castType})`supported castTypes andbehavior:CASTS={'int':lambdax:_cast_int(x),# see below'boolean':lambdax:bool(x),'string':lambdax:str(x),'float':lambdax:float(x),'json':lambdax:json.loads(x),# standard json library'none':lambdax:x,'null':lambdax:None}def_cast_int(obj):# fixes issues when trying to cast a float str -> int# int('1.09') throws ValueErrortry:returnint(obj)exceptValueError:returnint(float(obj))Split ListTakes a string at a given jsonpath and attempts to split it into an array of givendelimiterand casts the array items to a specificcastType. See valid casts in Cast section.The resolved pathmustbe a string.Will notoperate invidiually on array items in the case the path resolves to an array.usage:$.my.path.`splitlist({delimiter}, {castType})`MatchChecks the value found at a jsonpath against a providedmatch_term. If the value is not found, returns thenull_value. Will operate invidiually on array items in the case the path resolves to an array.usage:$.my.path.`match({match_term}, {null_value})`White space after commas is required!behavior:result=(value==match_term)ifvalue!=Noneelsenull_valueNot MatchProvides the inverse of Match. Checks the value found at a jsonpath against a providedmatch_term. If the value is not found, returns thenull_value. Will operate invidiually on array items in the case the path resolves to an array.usage:$.my.path.`notmatch({match_term}, {null_value})`White space after commas is required!behavior:result=(value!=match_term)ifvalue!=Noneelsenull_valueParse DatetimeAttempts to parse the iso formatted datetime from a string found at a given jsonpath. Then returns a part or the whole of the parsed datetime as specified by a python array slice.  Will operate invidiually on array items in the case the path resolves to an array. Thestrptime_strformat is taken from thepython strptime behavior. The array slice notation used inreturn_sliceis uses the standardslice operator, with semi-colon delimited arguments like:defargs_to_slice(cls,return_slice,obj):defaults=[0,None,None]parts=[]forx,iinenumerate(return_slice.split(':')):try:parts.append(int(i))exceptValueError:parts.append(defaults[x])returnobj[slice(*parts)]usage:$.my.path.`datetime({strptime_str}, {return_slice})`White space after commas is required!Parse Epoch TimestampAttempts to parse the epoch timestamp from a value found at a given jsonpath. Then returns a part or the whole of the parsed datetime as specified by a python array slice.  Will operate invidiually on array items in the case the path resolves to an array. The input units must be indicated as one of:secondsmillismicrosThe array slice notation used is the same as indatetime.usage:$.my.path.`epoch({units}, {return_slice})`White space after commas is required!HashReturns a 128bit, hex formatted MD5 hash of the value of a resolved jsonpath added to a providedsalt. This is useful for generating a UUID compatable value from a piece of source information along with some unique salt. This allows for a non-UUID foreign key to be reliably converted to the same UUID compatable value every time. Will operate invidiually on array items in the case the path resolves to an array.usage:$.my.path.`hash({salt})`TemplateWill substitue the value found at a resolved jsonpath into a formatted string with a singe replacement place holder. Will operate invidiually on array items in the case the path resolves to an array.usage:Using of format resembling:my name is {}$.my.path.`template({template_format)`Value ReplaceReplaces resolved values matchingmatch_valuewithreplacement_value. Will operate invidiually on array items in the case the path resolves to an array.usage:$.my.path.`valuereplace({match_value}, {replacement_value})`White space after commas is required!behavior:replacement_valueif(match_value==value)elsevalueDictionary ReplaceReplaces resolved values matching a key in a passed dictionary with the appropriate value from the same dictionary. Will operate invidiually on array items in the case the path resolves to an array. The dictionary argument should be a stringified python dictionary.usage:$.my.path.`dictionaryreplace({stringified_python_dictionary})`result is: path value replaces with value of matching key in dictionarybehavior:returnpassed_dict.get(value,None)