Translating FileMaker rich text to/from JSON via JavaScript

Document created by steve_ssh on Jul 13, 2018Last modified by steve_ssh on Sep 3, 2018
Version 9Show Document
  • View in full screen mode



This document is to share a pair of companion custom functions that I wrote in response to this post:



The functions translate FileMaker rich text content into a format which can be expressed using just plain text.  As in the post above, use cases could include any scenario where text formatting needs to be preserved as the data is passed through, or stored in, a system which doesn't naturally or easily support FileMaker's rich text data.




  • These functions are JavaScript-based, and rely upon a plug-in to evaluate JavaScript code (e.g. bBox, BaseElements, MBS)

  • Though I have been careful to code everything to be platform-agnostic, I have not tested these functions on Windows.



Two custom functions, plus a JavaScript plug-in wrapper function (to allow for use with more than one plug-in):




Brief video overview:



Final thoughts:


I, personally, have ever run into a need for this type of functionality perhaps only once or twice.  Despite the potential for only limited need, I thought it would be both fun and productive to write some JavaScript-based CF's, so that I could think about how to best package the code.  The aim was to have it be friendly to both developers who would desire to go in and tinker with the JS code, as well as those who simply wish to use it without any regard to how it works.


Additionally, I thought it might be helpful to put one more example out into the world which illustrates how a feature such as the one discussed here might be put to use.  These days I see a real nice surge of enthusiasm for JavaScript and FileMaker together, and I think that the more we can see different possibilities that are available, the more we will all grow and benefit as we combine these two technologies.


Thanks for taking a look, and thanks to all those sharing their JavaScript enthusiasm, abilities, and expertise.


Updates To Attached Archive:



01 Sept 2018


Updated archive to address an issue whereby the decoding process would break if either of the following two characters appears in the original rich text:


    • 'DOUBLE LOW-9 QUOTATION MARK'  (Unicode 201E)



      Sincere thanks to hhenle for discovering and reporting this issue.

03 Sept 2018


Added updated archive with new version of CF which supports additional FMP text styles:


   • HighlightYellow

   • Condense

   • Extend

   • SmallCaps

   • Uppercase

   • Lowercase

   • Titlecase


This update also provides imperfect support for text styles:


   • Subscript

   • Superscript.


Important Note:


When translating to and from Rich Text, subscript and superscript text will increase by one point size in cases where the original font size is an odd-numbered value.  This is due to a rounding effect that happens in the GetAsCSS function.  In cases where the original font size is an even-numbered value, or in cases where neither the superscript nor the subscript style has been applied, font size should be properly preserved.


Other Comments:


I suspect that I might have originally refrained from adding all of the styles not only out of laziness, but also because including all the possible styles increases the size of the JSON output.  For this reason, I am not deleting the previously updated version of the archive which only translates what I considered to be the most common styles at the time when I created the CFs.





Once again, sincere thanks goes to hhenle for motivating this update, providing examples of how it could work, and examples of cases where special adjustments to the code were necessary.  Thank you, Hubert!

9 people found this helpful