Delphi: Parsing JSON from RESTful APIs

Posted

I recently discovered that the new Filemaker Server version 18 has a much improved REST api service built right into the technology stack so I’ve been spending some free time writing Delphi code to see if I could successfully make calls to that service, parse out the results and then actually do something useful with them.

While I probably wouldn’t deploy a Filemaker Server instance into production as a legit backend database service (some people do…eww), the drag-and-drop designer portion of the software makes the Admin / Schema Design part of development super convenient for throwaway apps. Hell, enabling API services on any ‘database’ is just 2 clicks away. I like the convenience of that…. A LOT.

As you can see, the initial results are promising — at the very least I am able to successfully send a request for a server authentication token and then use that authentication token to send out a GET request and pull down some real data to work with.

Using stock Delphi components, the process works like this:
From Filemaker — an authenticated GET api call returns a JSON response / TJSONObject. We extract the “data” array from the JSON object into a TJSONArray and then programmatically create a TClientDataSet by looping through the JSON Array and finally piping it into a TDataConnection. From there we can make a simple connection to a DBGrid and voila. Records get displayed and we’re all happy.

I threw together a little git repo in case someone else happens to find this useful. I’m not really planning on pulling down the Filemaker API server anytime soon so it SHOULD still work. Regardless, the code is simple enough that you can probably follow it without too much trouble.

https://github.com/jyoung4225/delphi_json_example

Author
Categories