Convert JSON Data to COBOL Classes

Note: The following applies to .NET COBOL only.

Enterprise Developer enables you to automatically convert JSON data and generate COBOL classes when you paste the data into a COBOL file which is part of a .NET COBOL project.

  1. Copy the JSON data from your JSON source file.
  2. In Visual Studio, double-check the settings in Tools > Options > Micro Focus COBOL > Code Style > Formatting > General. These settings control how Visual Studio applies formatting to code you paste in the editor.
  3. In Visual Studio, open a COBOL file from a .NET COBOL project.
  4. Position the cursor in the file where you want to insert the generated data.
  5. Click Edit > Paste Special > Paste JSON As Classes.

    This converts your JSON data to COBOL classes and adds it to the COBOL file.

The class and property names are generated as follows:

Example

The following example shows the result of converting some film data in JSON format to COBOL classes using Paste JSON As Classes:

JSON code COBOL classes
{
    "$schema":"http:\/\/json-schema.org\/draft-04\/schema#",
	"title": "JSON restful schema for film library Operations",
	"type": "object",
	"properties": 
	{
		"film-details": 
		{
			"type": "array",
			"minItems": 1,
			"items": 
			{
				"type": "object",
				"properties": 
				{
					"title": 
					{
						"type": "string",
						"maxLength": 60
					},	
					
					"year": 
					{
						"type": "string",
						"maxLength": 4
					},						
					
					"director": 
					{
						"type": "string",
						"maxLength": 20
					},

					"format": 
					{
						"type": "string",
						"maxLength": 10
					}
				},
				"required":[
					"title",
					"year",
					"director",
					"format"
				]
			}
		}
	}
}
       class-id Rootobject.
       01 schema string property.
       01 #title string property.
       01 #type string property.
       01 #properties type Properties property.
       end class.

       class-id Properties.
       01 filmdetails type FilmDetails property.
       end class.

       class-id FilmDetails.
       01 #type string property.
       01 minItems binary-long property.
       01 items type Items property.
       end class.

       class-id Items.
       01 #type string property.
       01 #properties type Properties1 property.
       01 #required string occurs any property.
       end class.

       class-id Properties1.
       01 #title type Title property.
       01 year type Year property.
       01 director type Director property.
       01 #format type Format property.
       end class.

       class-id Title.
       01 #type string property.
       01 maxLength binary-long property.
       end class.

       class-id Year.
       01 #type string property.
       01 maxLength binary-long property.
       end class.

       class-id Director.
       01 #type string property.
       01 maxLength binary-long property.
       end class.

       class-id Format.
       01 #type string property.
       01 maxLength binary-long property.
       end class.