Parsing XML into JSON

In the world of serialized data, there's only been a few key technologies and XML was certainly the forerunner. It's been around since the mid 90's and was originally added into FileMaker around version 5 - if memory serves. The implementation of XML/XSLT/XPATH wasn't fully complete with compatible functions and it only works as an import and export feature via the use of an XSLT style sheet.

Learning XSLT and XPATH weren't the easiest things to do and as computing moved forward, so did other technologies. Now, with JSON and JavaScript taking the programming world by storm, we have a new method of serialization and this one is baked into FileMaker.

So, these days, you have the choice of learning xpath and using a plug-in in order to extract data out of XML or you can just convert it into a format such as JSON for simply pulling the data out using FileMaker 16's new JSON functions. With this technique file, and video, you'll be well on your way to extracting data out of XML files if you need to do so.

AttachmentSize
ParsingXMLintoJSON.zip1.59 MB

Comments

Matt....
In 16 set a $var to Base64Decode ( Base64EncodeRFC ( 4648 ; Table::containerField ) ) will get you the contents... Because you use no file name you get the contents..

This is a must know piece of info for any FileMaker developer needing to get the contents of a file stored within a container!

Thank you Matt for this brilliant video. Being able to convert XML to JSON natively is super useful now that we have the FM16 JSON functions.

Very nice technique, Matt. Thank you.
About grabbing containter data as per a comment above,
I've been using Base64Decode( Base64Encode( Table::containerField )), which works just as well when you don't need any particular format, as you won't in a back and forth case like this.

Hi there,
First of all, thank you for a great example.
Problem is with latin extended characters like ą ć etc. that are not imported.
Dou you have any solution or directions to fix this issue?

Have a nice day,
Bart

Just try to download older files. You'll get these errors quite a few times. The problem usually gets solved in a while.

I did a test with getting just the emails that were blacklisted on a clients website.
The website gave me JSON at first, then I had to parse the data to fill the records.
We are talking about 33k records:
JSON: 5+minutes.

Then I asked could I get a xml-response from the website:
xml import using xslt: 12 seconds for the same 33k records using import-update.

So that was about 30times faster.

Just my 0.02

Hello,

Thanx for a great job!

Since today i'm getting this error in a popup Windows window

"fmp://$/ParsingXMLintoJSON?script=ReceiveData&param=Error! Too many characters.
Check this out.
...://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters.... etc "

What's this error and how can I get rid of it?
Thank for your help
Regards