json.list2array ( )

Function stats

Average user rating
37
415
9999
Support
FileMaker 10.0 +
Date posted
18 November 2017
Last updated
19 November 2017
Version
Recursive function
No

Author Info
 Fabrice

76 functions

Average Rating 4.4

author_avatar



 

Function overview

Prototype

json.list2array  ( _list;   _type )


Parameters

_list  a ¶ delimited list


_type  a JSON type such as JSONString, JSONNumber…


Description

Tags:  List   Json  

converts a typical ¶ delimited list into a JSON array

Examples

Sample input

json.list2array ( "that's¶all¶folks" ; JSONString )


Sample output

[ "that's" ; "all" ; "folks" ]

 

Function code

/* json.list2array ( _list ; _type )
by Fabrice Nordmann, 1-more-thing
@1morethingtweet


converts a typical ¶ delimited list into a JSON array

json.list2array ( "that's¶all¶folks" ; JSONString ) ---> [ "that's" ; "all" ; "folks" ]


v2 - Nov 2017
    Uses json.array.append instead of CustomList
v1 - May 2017


*/

Case (
    IsEmpty ( _list ) ; "" ;
    ValueCount ( _list ) = 1 ; JSONSetElement ( "[]" ; 0 ; _list ; _type ) ;
    
Let ([
    $cf.type = Case ( not _type ; JSONString ; _type ) ;
    _first = LeftValues ( _list ; 1 ) ;
    _first = Left ( _first ; Length ( _first ) - 1 ) ;
    _last = RightValues ( _list ; 1 ) ;
    _last = Left ( _last ; Length ( _last ) - 1 ) ;
    _middle = MiddleValues ( _list ; 2 ; ValueCount ( _list ) -2 ) ;
    _middle = Left ( _middle ; Length ( _middle ) - 1 ) ;
    _eval.str = "json.array.append ( \"" & _middle & "\" ; $cf.type ; \"\" )" ;
    $eval.str = Substitute ( _eval.str ; ¶ ; "\" ; $cf.type ; \"\" ) & json.array.append ( \"" ) ;
    _result =
    
json.array.append ( _first ; $cf.type ; "INIT" ) &
Case ( ValueCount ( _list ) > 2 ; Evaluate ( $eval.str )) &
json.array.append ( _last ; $cf.type ; "END" ) ;
    $cf.type = "" ;
    $eval.str = ""

];
    _result
)
)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/415

    Prototype: json.list2array( _list; _type )
    Function Author: Fabrice (http://www.fmfunctions.com/mid/37)
    Last updated: 19 November 2017
    Version: 1.1

*/
// ===================================