Save a Copy as XML in UTF-8 or How to do the conversion

Hi Guys! Me again...
Ok, I try to convert the xml resulting from the script step: Save a Copy as XML to a JSON using the XML.ToJSON from MBS, but is imposible to convert the UTF-16 result from the Save a Copy as XML into a UTF-8 (or get rid from the funny chars at the beginning of the file).
I tried to read the contents from the container using TextDecode but surprisingly?? doesn't accept the utf-16 as encoding...
I tried Read from Data File to read directly from the disk but no success, tried XML.ReadContainer and XML.ReadFile from Monkey but no success.

I feel I am missing something obvious here, so I am stirring the soup again... :kissing_smiling_eyes:

Would you please post an example XML you're trying to convert to JSON?

Hi Oliver!
Is just a file from Tools > Save a copy as XML... or the script step Save a copy as XML

ContactsOriginalV1.xml.zip (125.1 KB)

Thanks. I'm sure @MonkeybreadSoftware will have some good suggestions for using his plug-in.

I personally tend to write my own code for these kinds of things (REST) where I have rich XML and JSON libraries -- all free. I call that code from FileMaker using INSERT FROM URL.

Best Regards,

1 Like

MBS knows "Plugin.LoadIconvLibrary" and iconv can convert UTF-16 to UTF-8. However, the description of this function doesn't mention if and how it can be used directly. The iconv CLI tool can convert a file with "iconv -f <enc> -t <enc> ...". Maybe you could just feed a text to the library, telling it what to convert from and to?

Sorry, there is "Text.ConvertFromTextEncoding" and "Text.ConvertToTextEncoding". But you also have to "Text.EncodeToHex" and "Text.DecodeFromHex", but I'm not sure how to combine it without testing...

Thanks Edwin! I will check those functions!

For the fun of it, I made a small test...

3 Likes