Site icon Embarcadero RAD Studio, Delphi, & C++Builder Blogs

Super Fast JSON Processing In Delphi With Winsoft.sk JSON Library

JSON is a text-based data format following JavaScript object syntax, which was popularized by Douglas Crockford. Even though it closely resembles JavaScript object literal syntax, it can be used independently from JavaScript, and many programming environments feature the ability to read (parse) and generate JSON. JSON exists as a string, and is useful when you want to transmit data across a network no matter System, Architecture or Programming Language.

One of the more powerful Libraries for handling JSON strings with Delphi is Winsoft JSON Library. Is very simple to use but very versatile to work with.

Menu Tools >Options >Language >Delphi >Library

Installation

Download the latest version here, and unzip the downloaded file to your default components folder.

This is a non-visual library, so you don’t need to install it on IDE.

Add a folder according to your Delphi version and Platform in Tools->Options->Language->Delphi->Library to Library Path

Sample

Generic JSON files viewer

Reading and parsing JSON Files

In the following example we are going to implement a generic JSON viewer that shows structure of the selected JSON file.

You can open this sample project at <Winsoft JSON Install Folder>\Examples\Delphi\VCL\Demo.dpr

The following code takes some steps to start parsing of a JSON file

  1. Load a JSON file you select from Open dialog
  2. Create instance of TJson object
  3. Load content from selected file to Tjson object via ParseUtg8File(OpenDialog.FileName)
  4. Call recursive function Show(nil, '' jsonItem) for root node
[crayon-6768c30d1d6c8467346244/]

This function starts checking node data type via some predefined item classes like TJsonNull, TJsonTrue, TJsonFalse, TJsonString and adding to Treeview. If the item being checked is an array, the TJsonArray function is called recursively with new parameters in order to add array elements as child of current item. Checking for TJsonObject add object properties to with current object as parent

[crayon-6768c30d1d6cf207605740/]

Like what you see? You can get JSON and over 100 other fantastic WinSoft components with our Enterprise Component Pack. For a limited time, when you purchase RAD Studio Enterprise or Architect Edition at special Upgrade Pricing, you will also get this package of third-party software worth over $13,000, including the full WinSoft Component Library, at NO EXTRA COST! Step up to RAD Studio 10.4 today!

Exit mobile version