Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated valid element test for GetValuesAtPath. #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions functions/JSON.GetValuesAtPath.fmfn
Original file line number Diff line number Diff line change
Expand Up @@ -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, [email protected], fixes gh #5, #4
* @history 2017-04-01, [email protected], created
*
Expand All @@ -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
If ( numObj < 1 or notValid ;
"" ;
List (
JSON.GetValuesAtPath ( newArray ; path ) ;
prop
)
)
)