Building Delphi Classes from JSON

JSON to Delphi Classes

I’m currently working on a new blog post showing how to integrate a popular REST API. One of my tasks is to convert JSON to Delphi Objects, so I need to define the Delphi class structures to work with so I can use the TJSON.JSONToObject that I covered previously. I decided to see if anyone had done work to convert JSON into Delphi classes.

Thankfully YES! I found this really handy project JsonToDelphiClass on GitHUB by . The project in covered in the post Introducing JsonToDelphiClass.

The JSON to Delphi Project is a Delphi FMX application that has a simple UI that allows you to modify the automatically created JSON class names which is pretty useful and the code worked first time when copied into my sample. (although I have more playing to do)

The JSON to Delphi tool is definitely a useful resource to work alongside the REST Debugger that you can find in the BIN directory of your RAD Studio install.

Stay tuned for the blog post when it arrives, but in the mean time, if your working with the REST components, I would recommend checking out Petar’s project along side my earlier post on Integrating Microsoft Azure Translation Services into Delphi.

 

8 thoughts on “Building Delphi Classes from JSON”

  1. I remember being really surprised that Delphi didn’t automate this, and a 3rd party utility was needed. In C# you you paste a json structure into a new file with a special menu command and it automagically creates a class definition. How did Embarcadero fail to notice this step was missing? Did they not use their own software?

  2. Have you looked at the Delphi MVC project. I believe it already has mappers for Pascal to JSON and JSON to Pascal.

Leave a Reply

Your email address will not be published. Required fields are marked *