Brian Dunning's FileMaker Custom Functions

cf_JSONrecord ( fieldList ; JSON )

This will take a record and recursively create the field and contents as a JSON object.

  Average rating: 5.0 (1 vote) Log in to vote

Jason Lecureux   Jason Lecureux - Show more from this author

Share on Facebook Share on Twitter

  Sample input:
cf_JSONrecord ( List ( "Contact::Key", "Contact::Name"); "" )

cf_JSONrecord ( FieldNames ( "File Name"; "Layout Name" ); "" )
  Sample output:
{"Contact::key": 12345,"Contact::Name": "Keith"}

{"field1": data,"field2": data,"field3": "data","field4": "data"}

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

You will also need the "Supertrim" custom function or some other way to remove the "\r" after the field name. (UPDATE: I've had better success with the Trim4 cf)
The "FieldNames" function pairs nicely if you want all the fields for a given record. Keep in mind this uses a layout to gather field names. If a field you want is in the table but not on the layout it won't show up.
This hasn't been tested with portal data.

 

Comments

belg4mit   belg4mit
Aug 19, 2022
Using SetElement's default variable type does not work for numerous field types including containers and fields with repetitions.; the latter would be best represented by an array.
 
Jason Lecureux   Jason Lecureux
Aug 22, 2022
Thank you for the response @belg4mit. I can't comment on the plausibility of having compatibility for those fields types. That is beyond my capabilities.
 
Kevin B   Kevin B
May 19, 2023
Hi there--Can you give me another example of the sample input? Is it just the field names separated by a comma? Thanks!
 
Jason Lecureux   Jason Lecureux
Oct 20, 2023
Hey Kevin, it's just looking for a list not comma separated fields.
 

Log in to post comments.

 

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

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: