All Projects → thomaserlang → delphi-json

thomaserlang / delphi-json

Licence: other
JSON parser for Delphi.

Programming Languages

pascal
1382 projects

Projects that are alternatives of or similar to delphi-json

xijs
A business - oriented scene Js Library
Stars: ✭ 91 (+21.33%)
Mutual labels:  json-parser
libstud-json
JSON pull-parser/push-serializer library for C++
Stars: ✭ 20 (-73.33%)
Mutual labels:  json-parser
marshmallow-objects
Marshmallow Objects and Models
Stars: ✭ 37 (-50.67%)
Mutual labels:  json-parser
jackson-js
JavaScript object serialization and deserialization library using decorators. It supports also advanced Object concepts such as polymorphism, Object identity and cyclic objects.
Stars: ✭ 86 (+14.67%)
Mutual labels:  json-parser
representable
Maps representation documents from and to Ruby objects. Includes JSON, XML and YAML support, plain properties and compositions.
Stars: ✭ 689 (+818.67%)
Mutual labels:  json-parser
format-to-json
An algorithm that can format a string to json-like template. 字符串JSON格式化的算法。
Stars: ✭ 30 (-60%)
Mutual labels:  json-parser
dora
JSON parser/explorer
Stars: ✭ 42 (-44%)
Mutual labels:  json-parser
util
封装了一些Java常用的功能
Stars: ✭ 19 (-74.67%)
Mutual labels:  json-parser
TwoWayMirror
Adapt Swift’s Mirror functionality to make it bidirectional.
Stars: ✭ 38 (-49.33%)
Mutual labels:  json-parser
mikrotik-json-parser
JSON parser library for RouterOS
Stars: ✭ 41 (-45.33%)
Mutual labels:  json-parser
ajson
Abstract JSON for Golang with JSONPath support
Stars: ✭ 144 (+92%)
Mutual labels:  json-parser
Cerializer
JSON Serializer using compile time reflection
Stars: ✭ 16 (-78.67%)
Mutual labels:  json-parser
JsonSwiftson
A JSON parser with concise API written in Swift.
Stars: ✭ 14 (-81.33%)
Mutual labels:  json-parser
domino-jackson
Jackson with Annotation processing
Stars: ✭ 46 (-38.67%)
Mutual labels:  json-parser
ZeroDepJson
A .NET Json parser in one .cs file, with zero dependencies.
Stars: ✭ 20 (-73.33%)
Mutual labels:  json-parser
Indian-States-and-Cities-Android
Offline Android App to illustrate Auto Complete Indian cities and states text views
Stars: ✭ 19 (-74.67%)
Mutual labels:  json-parser
coronavirus-dresden
Collects official SARS-CoV-2 infection statistics published by the city of Dresden.
Stars: ✭ 19 (-74.67%)
Mutual labels:  json-parser
hocon
go implementation of lightbend's HOCON configuration library https://github.com/lightbend/config
Stars: ✭ 49 (-34.67%)
Mutual labels:  json-parser
ajson
Yet another json parser serializer for ABAP
Stars: ✭ 29 (-61.33%)
Mutual labels:  json-parser
PowerJSON
Powerjson is json's improved data format.
Stars: ✭ 24 (-68%)
Mutual labels:  json-parser

JSON parser for Delphi

Why?

Didn't like the other Delphi JSON parsers out there. They seemed too complicated for the simple task i had for JSON.

So this is my go at it.

This version is only tested on Delphi XE 3, Delphi XE 6 (Android) and Delphi 10 but should work for all Delphi versions that support generics and TStringHelper.

What is missing

  • Exception if the JSON text is not valid.
  • Convert to string
  • Serialization and deserialization from/to objects.

Examples

Just include the djson.pas file in your uses list for this to work.

Example 1 - User

JSON

{
  "username": "thomas",
  "name": "Thomas",
  "photos": [
    {
      "title": "Photo 1",
      "urls": {
        "small": "http://example.com/photo1_small.jpg",
        "large": "http://example.com/photo1_large.jpg"
      }
    },
    {
      "title": "Photo 2",
      "urls": {
        "small": "http://example.com/photo2_small.jpg",
        "large": "http://example.com/photo2_large.jpg"
      }
    }
  ],
  "int_list": [
    1,
    2,
    3
  ]
}

Delphi

var
  user: TdJSON;
  photo: TdJSON;
  i: TdJSON;
begin
  user := TdJSON.parse({JSON_TEXT});
  try
    writeln('Username: '+ user['username'].AsString);
    writeln('Name: '+ user['name'].AsString);
    // Photos
    for photo in user['photos'] do
    begin
      writeln('Title: ' + photo['title'].AsString);
      writeln('Small url: ' + photo['urls']['small'].AsString);
      writeln('Large url: ' + photo['urls']['large'].AsString);
    end;

    // Int list
    for i in user['int_list'] do
    begin
      writeln(i.AsInteger);
    end;
  finally
    user.free;
  end;
end;

Example 2 - User list

JSON

[
  {
    "username": "thomas",
    "name": "Thomas"
  },
  {
    "username": "kurt",
    "name": "Kurt"
  },
  {
    "username": "bent",
    "name": null
  }
]

Delphi

var
  users: TdJSON;
  user: TdJSON;
begin
  users := TdJSON.Parse({JSON_TEXT});
  try
    for user in users do
    begin
      writeln(user['username'].AsString);
      if (not user['name'].IsNull) then
        writeln(user['name'].AsString);
    end;
  finally
    users.Free;
  end;
end;

LICENSE

The MIT License (MIT)

Copyright (c) 2018 Thomas Erlang

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].