Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

When writing expressions, macros or scripts you may need to enter a character that has special meaning. For example, a string could include a double-quote, but in the expression PhixFlow will read this as the end of the string. To tell PhixFlow to ignore a special character, you can use the backslash character.  

CharacterEscape string

backspace

 "\b"
"\\\\b"
form feed "\f"
"\\\\f"
tab"\t"
"\\\\t"
carraige return"\r"
"\\\\r"
newline"\n"
"\\\\n"
backslash

"\\\\"

"\\\\\\\\"
double quote'"'
'\\\\"'

Macro: Escaping Invalid Characters

...


Code Block
do(
    $value = $args[1],
    $value = replaceAll( $value , "\b","\\\\b"),
    $value = replaceAll( $value , "\f","\\\\f"),
    $value = replaceAll( $value , "\t","\\\\t"),
    $value = replaceAll( $value , "\r","\\\\r"),
    $value = replaceAll( $value , "\n","\\\\n"),
    $value = replaceAll( $value , "\\\\","\\\\\\\\"),
    $value = replaceAll( $value , '"','\\\\"')
)


Note: JSON Code can also include characters that cannot be written to the UTF-8 database such as Emojis which are 4 bit characters. This may be solved in the future by migrating the database to UTF-8mb4 but in the meantime, invalid characters can be removed using the following regular expression to do an initial validation on any JSON: 

replaceAll(JSON Code,"[^\\p{Space}0-9A-Za-z!:\\\"%&\\[*()\\],-/_\\\\{}\\.]","")

The expression contains a list of expected characters to be found in JSON files. Note how back slashes are used to escape special characters such as [] , . and \ 

See Regular Expressions


...