Software Venture Consulting

FileMaker Pro downloads & Resources
FileMaker Custom Functions
FileMaker Web Viewer Examples
FileMaker Pro & Lasso Consulting
Training
FileMaker Books
FileMaker Articles
FileMaker Error Reference

Free Web Tools
Free FileMaker Tools

Personal Pages
Videos
Adventures
Links

Shopping Cart
Shopping Cart

Search:

Free Newsletter
Signup


Contact


Privacy Policy



FileMaker is a registered trademark of FileMaker, Inc. in the U.S. and other countries.

 

 FileMaker Pro Custom Functions

List  |  Show Random  |  Upload  |  Add This to Your Site

padJSON (JSON ; rowLabels ; columnLabels )

Rate this function:  

RatingRatingRatingRatingRating
  Average rating: 4.3  (6 votes)
  Discuss this Custom Function

Michael Kupietz, FileMaker Pro Consultant, FileMaker Pro Consultant
http://www.bayareafilemakerconsulting.com

Pad out JSON string to two-dimensional array with null values

Sample Input:
"{\"A\":{\"1\":\"Hi\",\"3\":"there\"},"B":{\"1\":\"Hello\",\"4\":\"you\"}}"
Sample Output:
{\"A\":{\"1\":\"Hi\",\"2\":\"\",\"3\":there\"\",\"4\":\"\"},\"B\":{\"1\":\"Hello\",\"2\":\"\",\"3\":\"\",\"4\":\"you\"},\"C\":{\"1\":\"\",\"2\":\"\",\"3\":\"\",\"4\":\"\"},\"D\":{\"1\":\"\",\"2\":\"\",\"3\":\"\",\"4\":\"\"},\"E\":{\"1\":\"\",\"2\":\"\",\"3\":\"\",\"4\":\"\"}}


 Then copy & paste into FileMaker Advanced's Edit Custom Function window.

Click here to copy To Clip Manager if you have myFMbutler's Clip Manager installed

Description:

I needed a function to pad out JSON strings into full 2-dimensional arrays*, without overwriting existing data. For example, if:

$$JSON={"A":{"1":"Hi","3":"there"},"B":{"1":"Hello","4":"you"}}

then

padJSON ( $$JSON ; "A¶B¶C¶D¶E" ; "1¶2¶3¶4" ) =

{"A":{"1":"Hi","2":"","3":there"","4":""},"B":{"1":"Hello","2":"","3":"","4":"you"},"C":{"1":"","2":"","3":"","4":""},"D":{"1":"","2":"","3":"","4":""},"E":{"1":"","2":"","3":"","4":""}}

which is a full 5x4 array with existing keys for every permutation of the label lists "A¶B¶C¶D¶E" and "1¶2¶3¶4".

My reasons for needing this function are my own. I'm involved in some very dark JSON doings.

Note that this function has been needlessly complicated by the fact that FileMaker's value list functions insert garbage carriage returns... IE, rightvalues("A¶B¶C",1) is "C¶". So I I had to add the variables "theRightRowValues", "FileMakerFixRows", "theRightColValues", and "FileMakerFixCols" to work around this, marring the pristine beauty of my formerly elegant custom function. Oh well, it's a living.


(*Please note I am referring to an abstract tabular array of data, not a literal JSON array, which requires brackets. We apologize for any confusion caused. The parties responsible have been sacked.)

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

This is my Custom Function and I want to edit it

Discuss:

There was a glitch in the first version I posted. It would return a JSON error on the last row if you passed it a null value "" in the JSON field instead of a valid JSON string. Fixed now.

For now, it will probably still choke if you pass it invalid JSON, but at least if you pass it nothing it will reply with an valid empty, initialized JSON array. This way you can auto-enter initialized JSON arrays into text fields on creation.

Mike Kupietz, Bay Area, CA
July 07, 2017 8:57pm

Terminologically, you don't use brackets [], so it is not array.
https://www.w3schools.com/js/js_json_arrays.asp

19752, Japan
July 12, 2017 12:56am

It's not a JSON array. The data is a two-dimensional array, rows and columns of tabular data. In terms of the JSON structure, yes, it's stored in an ordinary JSON object, not a JSON array. I've added a clarification to that effect.

Michael E. Kupietz, FileMaker Consultant, San Francisco, CA
July 12, 2017 10:32pm

Make a comment about this Custom Function (please try to keep it brief & to the point). Anyone can post:

Your Name:
City/Location:
Comment:
characters left. If you paste in more than 1500 characters, it will be truncated. Discuss the function - advertisements and other useless posts will be deleted.
Answer 9 + 8 =
Search for Custom Functions:

Custom Functions Widget
Download the Custom Function Dashboard Widget for OS X
Keep all the latest Custom Functions right at your fingertips!

Newest Custom Functions:

1. decFromHex ( hexValue )
  (Mon, Oct 16, 12:34pm)
2. MonthYearList ( startmonth ; startyear ; numbermonth ; short )
  (Mon, Oct 16, 3:38am)
3. ErrorDescription ( errorNumber )
  (Wed, Sep 27, 2:51am)
4. decodeEntities (text)
  (Wed, Sep 27, 1:22am)
5. HexidecimalToNumber ( HexidecimalValue ; counter )
  (Mon, Sep 25, 12:39pm)
6. FixedFieldConverter ( Fieldname ; f1 ; f2 ; f3 ; f4 ; f5 ; f6 ; f7 ; f8 ; f9 ; f10 ; f11 ; f12 ; f13 ; f14 ; f15 ; f16 ; f17 ; f18 ; f1
  (Fri, Sep 15, 12:34pm)
7. ShannonEntropy ( text )
  (Thu, Sep 07, 5:59am)
8. LetterCount ( text ; summary )
  (Thu, Sep 07, 5:53am)

RSS Feed of Custom Functions