From f61c79233b9fef2312fee721d794c68b9cec0c63 Mon Sep 17 00:00:00 2001 From: Erik Shagdar Date: Wed, 15 Aug 2018 14:25:32 -0400 Subject: [PATCH] Updated valid element test for GetValuesAtPath. --- functions/JSON.GetValuesAtPath.fmfn | 38 ++++++++++++++++------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/functions/JSON.GetValuesAtPath.fmfn b/functions/JSON.GetValuesAtPath.fmfn index 0bfbcff..c73a3bc 100644 --- a/functions/JSON.GetValuesAtPath.fmfn +++ b/functions/JSON.GetValuesAtPath.fmfn @@ -3,11 +3,15 @@ * returns list containing only the values at that path * * @param {array} array a valid JSON Array of objects - * @param {string} the path to the property you want to list + * @param {path} the path to the property you want to list * * @module fm-json-additions * @see https://github.com/geistinteractive/fm-json-additions * + * @history 2018-08-15, eshagdar, NYHTC + * - Improved test for result of getting JSON element ( still not perfect, but better ). + * - Use If ( instead of Case ) for binary test. + * - Updated param documentation. * @history 2017-05-16, john@e-rwu.com, fixes gh #5, #4 * @history 2017-04-01, todd@geistinteractive.com, created * @@ -16,20 +20,20 @@ Let ( [ - - notValid = Left ( JSONFormatElements ( array ) ; 1 ) = "?" ; - c = ValueCount ( JSONListValues ( array ; "" ) ) ; + notValid = Left ( JSONFormatElements ( array ) ; 1 ) = "?" ; + numObj = ValueCount ( JSONListValues ( array ; "" ) ) ; + + thisItem = JSONGetElement ( array ; numObj - 1 ) ; + newArray = JSONDeleteElement ( array ; numObj - 1 ) ; + prop = JSONGetElement ( thisItem ; path ) ; + prop = If ( Left ( prop ; 26 ) = "? in Json::Value::operator" ; ""; prop ) + ]; - thisItem = JSONGetElement ( array ; c - 1 ) ; - newArray = JSONDeleteElement ( array ; c - 1 ) ; - prop = JSONGetElement ( thisItem ; path ) ; - prop = If ( Left ( prop ; 1 ) = "?" ; ""; prop ) - -]; - - Case ( - c < 1 or notValid ; "" ; - List ( JSON.GetValuesAtPath ( newArray ; path ) ; prop ) - ) //end case - -) //end let \ No newline at end of file + If ( numObj < 1 or notValid ; + "" ; + List ( + JSON.GetValuesAtPath ( newArray ; path ) ; + prop + ) + ) +) \ No newline at end of file