Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

JSON2DelphiRecord

[FireMonkey] make records from json data

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

JSON2DelphiRecord

[FireMonkey] make records from json data

ERROR №1 (The array elements must be in the format {"key": value})
pascal
{
  "telephones": ["000000000", "111111111111"]
}

CORRECT

pascal
{
  "telephones": [{"key":"000000000"}, {"key":"111111111111"}]
}

ERROR №2 (the array should be named)
pascal
[{"index":3},{"index":4},{"index":2},{"index":1}]

CORRECT

pascal
{
  "data": [{"index":3},{"index":4},{"index":2},{"index":1}]
}
ERROR №3 (NULL not supported)
pascal
{
  "menu":  
  {
    "header":"xProgress SVG Viewer",
    "items":[
      {
        "id":"OpenNew",
        "label":"Open New"      
      },
      null,
      {
        "id":"ZoomIn",
        "label":"Zoom In"      
      }    
    ]  
  }
}

Correct

pascal
{
  "menu":  
  {
    "header":"xProgress SVG Viewer",
    "items":[
      {
        "id":"OpenNew",
        "label":"Open New"      
      },
      {
        "id":"ZoomIn",
        "label":"Zoom In"      
      }    
    ]  
  }
}

Simple Object

pascal
{
  "A": 1,
  "B": "2",
  "C": 1.3,
  "D": false,
  "F": "2014-05-03T03:25:05.059"
}

Output

pascal
TmyTypeRecord = record
  A: integer;
  B: string;
  C: float;
  D: boolean;
  F: string;
end;

Objects

pascal
{"widget": {
    "debug": "on",
    "window": {
        "title": "Sample Konfabulator Widget",
        "name": "main_window",
        "width": 500,
        "height": 500
    },
    "image": { 
        "src": "Images/Sun.png",
        "name": "sun1",
        "hOffset": 250,
        "vOffset": 250,
        "alignment": "center"
    },
    "text": {
        "data": "Click Here",
        "size": 36,
        "style": "bold",
        "name": "text1",
        "hOffset": 250,
        "vOffset": 100,
        "alignment": "center",
        "onMouseUp": "sun1.opacity = (sun1.opacity / 100) * 90;"
    }
}}

Output

pascal
TmyTypeImage = record
  src: string;
  name: string;
  hOffset: integer;
  vOffset: integer;
  alignment: string;
end;

TmyTypeText = record
  data: string;
  size: integer;
  style: string;
  name: string;
  hOffset: integer;
  vOffset: integer;
  alignment: string;
  onMouseUp: string;
end;

TmyTypeWindow = record
  title: string;
  name: string;
  width: integer;
  height: integer;
end;

TmyTypeWidget = record
  debug: string;
  window: TmyTypeWindow;
  image: TmyTypeImage;
  text: TmyTypeText;
end;

TmyTypeRecord = record
  widget: TmyTypeWidget;
end;

Array

pascal
{"markers": [
        {
            "point": "new GLatLng(40.266044,-74.718479)",
            "homeTeam":"Lawrence Library",
            "awayTeam":"LUGip",
            "markerImage":"images/red.png",
            "information": "Linux users group meets second Wednesday of each month.",
            "fixture":"Wednesday 7pm",
            "capacity":"",
            "previousScore":""
        },
        {
            "point":"new GLatLng(40.211600,-74.695702)",
            "homeTeam":"Hamilton Library",
            "awayTeam":"LUGip HW SIG",
            "markerImage":"images/white.png",
            "information": "Linux users can meet the first Tuesday of the month to work out harward and configuration issues.",
            "fixture":"Tuesday 7pm",
            "capacity":"",
            "tv":""
        },
        {
            "point":"new GLatLng(40.294535,-74.682012)",
            "homeTeam":"Applebees",
            "awayTeam":"After LUPip Mtg Spot",
            "markerImage":"images/newcastle.png",
            "information": "Some of us go there after the main LUGip meeting, drink brews, and talk.",
            "fixture":"Wednesday whenever",
            "capacity":"2 to 4 pints",
            "tv":""
        }
] }

Output

pascal
TmyTypeMarkers = record
  point: string;
  homeTeam: string;
  awayTeam: string;
  markerImage: string;
  information: string;
  fixture: string;
  capacity: string;
  tv: string;
end;

TmyTypeRecord = record
  markers: TArray<TmyTypeMarkers>;
end;