First, in the help file, these commands are listed like this: JSon_StrEscape$ JSon_UnStrEscape$
But they don't actually work with the dollar signs attached.
I think they got confused with: Url_Escape$ Url_UnEscape$
which do have dollar signs.
Anywho, heres some examples for the man page, and a larger one for the SampleScripts folder.
' Example: JSon_StrEscape Function
Uses "Console"
Dim inputString, result As String
' Example 1: Quotes and backslashes
inputString = "Hello ""World"" with \backslashes\"
result = JSon_StrEscape(inputString)
PrintL "Original: " & inputString
PrintL "Escaped : " & result
PrintL
' Example 2: Control characters (newline, tab, carriage return)
inputString = "Line 1" & $CRLF & "Line 2" & $TAB & "Tabbed text"
result = JSon_StrEscape(inputString)
PrintL "Original:"
PrintL inputString
PrintL "Escaped : " & result
PrintL
' Example 3: Preparing string for JSON output
inputString = "User said: ""Hello!"" Path: C:\Users\John"
result = JSon_StrEscape(inputString)
PrintL "Original: " & inputString
PrintL "Escaped : " & result
PrintL "JSON : {\""message\"":\"" & result & ""\""}"
PrintL
WaitKey "Finished. Press any key to exit..."
' Example: JSon_StrUnEscape Function
Uses "Console"
Dim jsonString,result As String
' Example 1: Escaped quotes and backslashes
jsonString = "\""Hello \""World\"" with \\backslashes\\\"""
result = JSon_StrUnEscape(jsonString)
Printl "Original: " & jsonString
Printl "Result : " & result
Printl
' Example 2: Control characters (newline, tab, carriage return)
jsonString = "Line 1\\nLine 2\\tTabbed text\\rCarriage return"
result = JSon_StrUnEscape(jsonString)
Printl "Original: " & jsonString
Printl "Result :"
Printl result
Printl
' Example 3: Typical JSON data processing
jsonString = "{\""name\"":\""John\"",\""message\"":\""Hello\\nWorld!\"",\""path\"":\""C:\\\\Users\\\\John\""}"
result = JSon_StrUnEscape(jsonString)
Printl "JSON String: " & jsonString
Printl "Unescaped : " & result
PrintL
WaitKey "Finished. Press any key to exit..."
' ============================================================================
' THINBASIC Example Program - JSon_StrUnEscape Function Demo
'
' This program demonstrates how to use the JSon_StrUnEscape function
' to transform JSON strings by unescaping special characters
' ============================================================================
Uses "Console"
' Display program header
PrintL "THINBASIC JSon_StrUnEscape Function Example"
PrintL String$(50, "=")
PrintL
' Declare variables
Dim originalJsonString, unescapedString As String
Dim counter As Long
' Example 1: Basic escaped quotes and backslashes
PrintL "Example 1: Escaped quotes and backslashes"
PrintL String$(45, "-")
originalJsonString = "\""Hello \""World\"" with \\backslashes\\\"""
unescapedString = JSon_StrUnEscape(originalJsonString)
PrintL "Original JSON String: " & originalJsonString
PrintL "Unescaped String : " & unescapedString
PrintL
' Example 2: Control characters (newline, tab, carriage return)
PrintL "Example 2: Control characters"
PrintL String$(30, "-")
originalJsonString = "Line 1\\nLine 2\\tTabbed\\rCarriage Return"
unescapedString = JSon_StrUnEscape(originalJsonString)
PrintL "Original JSON String: " & originalJsonString
PrintL "Unescaped String :"
PrintL unescapedString
PrintL
' Example 3: Form feed and backspace characters
PrintL "Example 3: Form feed and backspace"
PrintL String$(35, "-")
originalJsonString = "Text with\\fform feed and\\bbackspace"
unescapedString = JSon_StrUnEscape(originalJsonString)
PrintL "Original JSON String: " & originalJsonString
PrintL "Unescaped String : " & unescapedString
PrintL
' Example 4: Forward slash (optional escaping)
PrintL "Example 4: Forward slash escaping"
PrintL String$(34, "-")
originalJsonString = "URL: https:\\/\\/www.example.com\\/path"
unescapedString = JSon_StrUnEscape(originalJsonString)
PrintL "Original JSON String: " & originalJsonString
PrintL "Unescaped String : " & unescapedString
PrintL
' Example 5: Complex JSON-like string with multiple escape sequences
PrintL "Example 5: Complex example with multiple escapes"
PrintL String$(48, "-")
originalJsonString = "{\""message\"":\""Hello\\nWorld!\"",\""path\"":\""C:\\\\Users\\\\John\"",\""tab\"":\""Item\\tValue\""}"""
unescapedString = JSon_StrUnEscape(originalJsonString)
PrintL "Original JSON String: " & originalJsonString
PrintL "Unescaped String : " & unescapedString
PrintL
' Example 6: Processing an array of JSON strings
PrintL "Example 6: Processing multiple JSON strings"
PrintL String$(42, "-")
Dim jsonStrings(5) As String
jsonStrings(1) = "\""First item with \""quotes\""\"""
jsonStrings(2) = "\""Second\\nitem\\nwith\\nnewlines\"""
jsonStrings(3) = "\""Third\\titem\\twith\\ttabs\"""
jsonStrings(4) = "\""Path: C:\\\\Program Files\\\\MyApp\"""
jsonStrings(5) = "\""Mixed: \""Hello\""\\n\\tWorld!\"""
For counter = 1 To 5
PrintL "JSON String " & Str$(counter) & ":"
PrintL " Original : " & jsonStrings(counter)
PrintL " Unescaped: " & JSon_StrUnEscape(jsonStrings(counter))
PrintL
Next counter
' Example 7: Error handling - empty string
PrintL "Example 7: Edge cases"
PrintL String$(21, "-")
' Empty string
originalJsonString = ""
unescapedString = JSon_StrUnEscape(originalJsonString)
PrintL "Empty string result: '" & unescapedString & "'"
' String with no escape sequences
originalJsonString = "Simple string with no escapes"
unescapedString = JSon_StrUnEscape(originalJsonString)
PrintL "No escapes result : '" & unescapedString & "'"
PrintL
' Practical example: Processing JSON data from a file or API
PrintL "Example 8: Practical JSON processing simulation"
PrintL String$(49, "-")
' Simulate JSON response data
Dim jsonResponse As String
jsonResponse = "{\""name\"":\""John Doe\"",\""message\"":\""Welcome!\\nPlease check your C:\\\\Documents folder.\"",\""timestamp\"":\""2024-01-15\\t10:30:00\""}"
PrintL "Simulated JSON Response:"
PrintL jsonResponse
PrintL
PrintL "After JSon_StrUnEscape processing:"
PrintL JSon_StrUnEscape(jsonResponse)
PrintL
WaitKey "Finished. Press any key to exit..."