Repeating fields in a Postman body

We are testing sending a POST request to our mainframe (a COBOL program).
Cobol allows the concept of repeating fields, so, for example, a definition such as (in COBOL)
05 repeating-field occurs 2.
10 field1 pic xx.
10 field2 pic 99.

would result in the conceptual memory contents of xx99xx99 (ie, 4 bytes repeated twice).
I have no idea how to define this as raw data in the body of a Postman request.
I have generated code similar to the following

{                                                                 
  "quantity_of_loan": 999999999,                 <----- first field in body    
    {                                                
      "code_type_of_loan": "xx",                     
      "amount_current_debt": 99999999,               
      "code_type_of_loan": "xx",                     
      "amount_current_debt": 99999999,                        
    }                                                
    {                                                
      "personal_number": "xxxxxxxxxxxx",             
      "task_timestamp": "xxxxxxxxxxxxxxxxxxxxxxxxxx",   <---- last field in body
}

where the idea is that code_type_of_loan and amount_current_debt are two fields repeated twice.

If this definition is correct (yeah, right), then a couple of questions

  1. I’m guessing that the second line with “amount_current_debt”: 99999999, shouldn’t (?) have a trailing comma ?

  2. Likewise the task_timestamp line ???

1 Like

Assuming you’ve fiddled with this a bunch, what sort of responses are you getting, and do they differ when you have or don’t have the comma? I’m shooting in the dark here but maybe that would add more context?

Thank you Hannah. My problem is that I’m trying to help a colleague who is even more of a newbie at Postman than I am. In his case, he is converting a program that used XML schemas to JSON/Swagger. In addition, neither of us have “written” a POST request.

To compound the problem, his request requires about 20-30 fields to be sent in, so for that reason, we’re going down the road of the define the arguments/values in the body as
{
“field1”: “character_value1”,
“field2”: numeric_value2.
etc etc
}

The problem we’re having is the COBOL concept of repeating fields in the body.
In COBOL, the example fields above would be referred to code_type_of_loan(1) and code_type_of_loan(2) to indicate which “row” in the table they’re in.

Since my understanding is that each entry in the body (field1) must correspond to an entry in the schema, and since the Swagger is defined as something like
“CreateLoanRequestRemainingDebtType”:
{“description”: “Contains up to 2 CreateLoanRequestRemainingDebtType”,
“type”: “array”,
“maxItems”:2,
“minItems”:0,
“items”:
“type”: “object”,
“properties”: {
{
{
“name”: “code_type_of_loan”,
“description”: “code_type_of_loan”,
“type”:“string”,
“maxLength”:2,
“minLength”:2
},
{
“name”: “amount_current_debt”,
“description”: “amount_current_debt”,
“type”: “integer”,
“maximum”:99999999,
“minimum”:0
},

My question remains. How do you define each code_type_of_loan/amount_current_debt value in the Postman body.

Would it make any difference if we used a file as the input to the body?

Hi @aviation-observer-15,
Do you have the Swagger JSON file already? If yes, then you needn’t worry about converting it into a request on Postman because there is an option to generate a collection from Swagger(including schema file formats) - https://learning.postman.com/docs/designing-and-developing-your-api/the-api-workflow/#generating-a-collection :crossed_fingers:

1 Like

Thank you Meenakshi.
If I understand you correctly, are you saying that by following the instructions in your link (we do have the Swagger file), I can then generate a request using the Swagger file and that generated request will automatically show me how to define the repeating fields in the request body (or at least show me how define element1 and element2 in the body)?

Ideally yes. Can you try importing the swagger file and generating the collection? And then I’ll know for sure :grinning_face_with_smiling_eyes:

Okay, we have (generated from COBOL copybook definitions) the Swagger file, but when I load it into Notepad++ and try to format it, I get an error. Here is one field above and then the array with its 2 components that is failing.Note that this code is placed in what I call the “input” area, and NOT AFTER the definitions line

          "name": "electronic_identified_flag",
          "in": "query",
          "description": "FL-EL-IDENT - electronic identified flag",
          "required": "true",
          "type": "string",
          "maxLength": 1,
          "minLength": 1
        },          
        {
          "name": "SKULD-list",
          "in": "query",
          "description": "Contains up to 3 JPB172-SKULD",
          "type":"array",
          "maxItems": 3,
          "minItems": 0,
          "items":
            {
              "type": "object",
              "properties":
                {
                  "name": "code_type_of_loan",
                  "in": "query",
                  "description": "KD-SKULD - code type of loan",
                  "required": "true",
                  "type": "string",
                  "maxLength": 2,
                  "minLength": 2
                },
                {          <------ this is the line that JSON Viewer Format option complains about
                  "name": "amount_current_debt",
                  "in": "query",
                  "description": "SU-SKULD - amount current debt",
                  "required": "true",
                  "type": "integer",
                  "maximum": 99999999,
                  "minimum": 0
                },

If you look at this and wonder “why on earth is Michael doing it this way”, it’s because I’ve only worked with JSON/Swagger and schemas these last 3 months, so there might well be stuff I have no idea about.
I’ll experiment by taking the array out of the input area, but I assume you can send an array in in the same way you can send one out?

Okay, been playing a bit based on what I’ve been able to Google (you guys have no idea what it was like before Google was available :grinning:), and this is what I’ve arrived at

				"parameters": [
				{
					"name": "electronic_identified_flag",
					"in": "query",
					"description": "FL-EL-IDENT - electronic identified flag",
					"required": "true",
					"type": "string",
					"maxLength": 1,
					"minLength": 1
				},
				{
					"name": "skuld_list",
					"description": "Contains up to 3 JPB172-SKULD",
					"type": "array",
					"maxItems": 3,
					"minItems": 0,	
					"example":{{
						"code_type_of_loan": "Triple",
						"amount_current_debt": 999,
					},{
						"code_type_of_loan": "",
						"amount_current_debt": 0
					}},	
					"items": {
						"property": {
							"property": "code_type_of_loan",
							"description": "KD-SKULD - code type of loan",
							"required": "true",
							"type": "string",
							"maxLength": 2,
							"minLength": 2
						},
						"property": {
							"property": "amount_current_debt",
							"description": "SU-SKULD - amount current debt",
							"required": "true",
							"type": "integer",
							"maxLength": 99999999,
							"minLength": 0
						}
					}
				}
			],
			"responses": {

The code above fails, but if I remove the line starting at “example”: and up to but excluding the “items”: it formats okay.
Can anyone tell me what is wrong with “example”: code ?

I found the example code at How do I create an array of objects, showing multiple to convey that it will accept multiple · Issue #728 · zircote/swagger-php · GitHub, but I couldn’t really follow bfanger comments. In the example definition, he has “firstName”, “lastName”, “company” and “id”, but then in the Property definitions he has 5 elements (?) called “firstName”, “lastName”, “companyId”, “accountNumber” and “netPay”.
Was he just being a bit sloppy or am I m isunderstanding something?

In the meantime, I’ll remove the example code and follow your suggestion Meenakshi and see how far I get

Here’s an extract from my Swagger file and I set OpenAPI 2.0 to “true”

{
"name": "skuld_list",
"in": "query",
"description": "Contains up to 3 JPB172-SKULD",
"type": "array",
"maxItems": 3,
"minItems": 0,
"items": {
	"property": {
		"name": "code_type_of_loan",
		"description": "KD-SKULD - code type of loan",
		"required": true,
		"type": "string",
		"maxLength": 2,
		"minLength": 2
	},
	"property": {
		"name": "amount_current_debt",
		"description": "SU-SKULD - amount current debt",
		"required": true,
		"type": "integer",
		"maxLength": 99999999,
		"minLength": 0
	}
}

},

Trouble is, I’m getting an error message pointing to the first property entry after items: with the message Contains an invalid property: property

Any suggestions ?

A follow-on to my posts. My Swagger file returns no errors from https://www.jsonschemavalidator.net/ but returns the error above from Postman. Is there a discrepancy in the JSON Schema standard supported in Postman or is there some way I can set it such that Postman is happy with the layout?

For the sake of honesty, I have to mention that I pasted the same JSON code into https://editor.swagger.io/ and it returned a duplicated mapping key (still trying to figure that out)

Can you add the full schema , what ever json you you have given is incomplete

By all means (and I appreciate you taking the time to look at this).

Remember the following points.
Pasting this into then json schema validator will give no errors
Pasting it into Postman gives “complaints” about invalid property (2 messages)
Pasting it onto editor swagger gives 3 errors.

As I’ve mentioned before, if you see anything that makes you wonder why I’m doing it one way or the other, keep in mind that I’d never heard of Swagger 3 months ago.

{
  "swagger": "2.0",
  "info": {
    "title": "xxx.Bank.MFBank.Securities",
    "version": "1.0.0",
    "description": "Get securities"
  },
  "host": "ourhost",
  "basePath": "/our/url",
  "schemes": [
    "https"
  ],
  "paths": {
		"/": {
			"post": {
				"tags": ["JPB172"],
				"summary": "",
				"description": "endpoint desc",
				"produces": ["application/json"],
				"parameters": [
					{
						"name": "campaign_identity",
						"in": "query",
						"description": "ID-KAMPANJ - campaign identity",
						"required": true,
						"type": "integer",
						"maximum": 9999,
						"minimum": 0
					},
					{
						"name": "approved_process_date",
						"in": "query",
						"description": "DA-GODKAND - process date approved",
						"required": true,
						"type": "string",
						"maxLength": 10,
						"minLength": 10
					},
					{
						"name": "approved_process_time",
						"in": "query",
						"description": "TI-GODKAND - process time approved",
						"required": true,
						"type": "string",
						"maxLength": 8,
						"minLength": 8
					},
					{
						"name": "amount_loan",
						"in": "query",
						"description": "BL-LANEBELOPP - loan amount",
						"required": true,
						"type": "integer",
						"maximum": 999999999,
						"minimum": 0
					},
					{
						"name": "granted_amortization_period",
						"in": "query",
						"description": "TI-LAN-AMORT - granted amortization period",
						"required": true,
						"type": "integer",
						"maximum": 999,
						"minimum": 0
					},
					{
						"name": "solve_client_credits",
						"in": "query",
						"description": "BL-LAN-LOSA - solve client credits",
						"required": true,
						"type": "integer",
						"maximum": 999999999,
						"minimum": 0
					},
					{
						"name": "service_accountno_ica",
						"in": "query",
						"description": "ID-KONTONR-SERV - service accountno ica",
						"required": true,
						"type": "string",
						"maxLength": 11,
						"minLength": 11
					},
					{
						"name": "loan_object",
						"in": "query",
						"description": "KD-SY-LAN - loan object",
						"required": true,
						"type": "string",
						"maxLength": 2,
						"minLength": 2
					},
					{
						"name": "resident_code",
						"in": "query",
						"description": "KD-BOENDE - resident code",
						"required": true,
						"type": "string",
						"maxLength": 2,
						"minLength": 2
					},
					{
						"name": "resident_expences",
						"in": "query",
						"description": "SU-BOENDE-KOSTN - resident expences",
						"required": true,
						"type": "integer",
						"maximum": 999999,
						"minimum": 0
					},
					{
						"name": "number_of_children",
						"in": "query",
						"description": "KD-ANTAL-BARN - number of children",
						"required": true,
						"type": "string",
						"maxLength": 2,
						"minLength": 2
					},
					{
						"name": "child_expences",
						"in": "query",
						"description": "BL-UNDERH-KOSTN - child expences",
						"required": true,
						"type": "integer",
						"maximum": 999999,
						"minimum": 0
					},
					{
						"name": "monthly_alimony",
						"in": "query",
						"description": "BL-UNDERH-INK - monthly alimony",
						"required": true,
						"type": "integer",
						"maximum": 999999,
						"minimum": 0
					},
					{
						"name": "electronic_identified_flag",
						"in": "query",
						"description": "FL-EL-IDENT - electronic identified flag",
						"required": true,
						"type": "string",
						"maxLength": 1,
						"minLength": 1
					},
					{
						"name": "skuld_list",
						"in": "query",
						"description": "Contains up to 3 JPB172-SKULD",
						"type": "array",
						"maxItems": 3,
						"minItems": 0,
						"items": {
							"property": {
								"name": "code_type_of_loan",
								"description": "KD-SKULD - code type of loan",
								"required": true,
								"type": "string",
								"maxLength": 2,
								"minLength": 2
							},
							"property": {
								"name": "amount_current_debt",
								"description": "SU-SKULD - amount current debt",
								"required": true,
								"type": "integer",
								"maxLength": 99999999,
								"minLength": 0
							}
						}
					},
					{
						"name": "pers-list",
						"in": "query",
						"description": "Contains up to 2 JPB172-PERS-IN",
						"type": "array",
						"maxItems": 2,
						"minItems": 0,
						"items": {
							"property": {
								"name": "personal_number",
								"description": "ID-PERSNR - personal number",
								"required": true,
								"type": "string",
								"maxLength": 12,
								"minLength": 12
							},
							"property": {
								"name": "task_timestamp",
								"description": "TI-UPPGIFT - task timestamp",
								"required": true,
								"type": "string",
								"maxLength": 26,
								"minLength": 26
							},
							"property": {
								"name": "first_name",
								"description": "BE-FNAMN - customer's first name",
								"required": true,
								"type": "string",
								"maxLength": 15,
								"minLength": 15
							},
							"property": {
								"name": "last_name",
								"description": "BE-ENAMN - customer's last name",
								"required": true,
								"type": "string",
								"maxLength": 27,
								"minLength": 27
							},
							"property": {
								"name": "street_address",
								"description": "AD-UTDELN - street address",
								"required": true,
								"type": "string",
								"maxLength": 35,
								"minLength": 35
							},
							"property": {
								"name": "zip_code",
								"description": "ID-POSTNR - zip code",
								"required": true,
								"type": "integer",
								"maximum": 99999,
								"minimum": 0
							},
							"property": {
								"name": "postal_address",
								"description": "AD-POSTSTN - postal address",
								"required": true,
								"type": "string",
								"maxLength": 20,
								"minLength": 20
							},
							"property": {
								"name": "co_attn_name",
								"description": "BE-NAMN-CO-ATT - co_attn_name",
								"required": true,
								"type": "string",
								"maxLength": 35,
								"minLength": 35
							},
							"property": {
								"name": "home-phone_number",
								"description": "AD-TELENR - home phone number",
								"required": true,
								"type": "string",
								"maxLength": 15,
								"minLength": 15
							},
							"property": {
								"name": "cell-phone_number",
								"description": "AD-MOBILNR - cell phone number",
								"required": true,
								"type": "string",
								"maxLength": 15,
								"minLength": 15
							},
							"property": {
								"name": "email_address",
								"description": "AD-EMAIL - email address",
								"required": true,
								"type": "string",
								"maxLength": 80,
								"minLength": 80
							},
							"property": {
								"name": "code_authentication",
								"description": "KD-AUTENT-KUND - code authentication",
								"required": true,
								"type": "string",
								"maxLength": 2,
								"minLength": 2
							},
							"property": {
								"property": "code_occupation",
								"description": "KD-SYSSELSATTNING - code occupation",
								"required": true,
								"type": "string",
								"maxLength": 2,
								"minLength": 2
							},
							"property": {
								"name": "monthly_income",
								"description": "BL-INKOMST - monthly income",
								"required": true,
								"type": "integer",
								"maximum": 999999999,
								"minimum": 0
							},
							"property": {
								"name": "code_loan_protection",
								"description": "KD-LANESKYDD - code loan protection",
								"required": true,
								"type": "string",
								"maxLength": 1,
								"minLength": 1
							},
							"property": {
								"name": "political_exposed",
								"description": "FL-PEP - political exposed",
								"required": true,
								"type": "string",
								"maxLength": 1,
								"minLength": 1
							},
							"property": {
								"name": "code_marital_status",
								"description": "KD-CIVILSTAND - code marital status",
								"required": true,
								"type": "string",
								"maxLength": 1,
								"minLength": 1
							},
							"property": {
								"name": "employer",
								"description": "BE-ARBETSGIVARE - employer",
								"required": true,
								"type": "string",
								"maxLength": 50,
								"minLength": 50
							},
							"property": {
								"name": "employer_phone_no",
								"description": "AD-TELENR-A - employer_phone_no",
								"required": true,
								"type": "string",
								"maxLength": 15,
								"minLength": 15
							},
							"property": {
								"name": "year_of_employment",
								"description": "DA-ANST-AAAA - year of employment",
								"required": true,
								"type": "integer",
								"maximum": 9999,
								"minimum": 0
							},
							"property": {
								"name": "resident_country_code",
								"description": "KD-LAND-BOSATT - resident country code",
								"required": true,
								"type": "string",
								"maxLength": 2,
								"minLength": 2
							},
							"property": {
								"name": "currency_code",
								"description": "KD-VALUTA - currency code",
								"required": true,
								"type": "string",
								"maxLength": 3,
								"minLength": 3
							}
						}
					}
				],
				"responses": {
					"200": {
be s						"description": "If the value in the argument passed in is 
valid, a response will ent back",
						"schema": {
							"$ref": "#/definitions/JPB172_response"
						}
					}
				},
				"x-auth-type": "Application & Application User",
				"x-throttling-tier": "Unlimited"
			}
		}
	},
	"definitions": {
		"JPB172_response": {
			"type": "object",
			"properties": {
				"assignment_number": {
					"description": "ID-ARENDE - assignment number",
					"type": "integer",
					"maximum": 999999999,
					"minimum": 0
				},
				"resolution_code": {
					"description": "KD-BESLUT - resolution code",
					"type": "string",
					"maxLength": 1,
					"minLength": 1
				},
				"resolution_reason-code": {
					"description": "KD-BESLUT-ORSAK - resolution reason code",
					"type": "integer",
					"maximum": 999,
					"minimum": 0
				},
				"employment_code": {
					"description": "KD-ANSTALLD - emoloyment code",
					"type": "string",
					"maxLength": 1,
					"minLength": 1
				},
				"campaign_identity_response": {
					"description": "ID-KAMPANJ-UT - campaign identity response",
					"type": "integer",
					"maximum": 9999,
					"minimum": 0
				},
				"credit_code_head": {
					"description": "KD-KRE-STYR - credit code head",
					"type": "string",
					"maxLength": 6,
					"minLength": 6
				},
				"PERS-list": {
					"description": "Contains up to 2 JPB172-PERS-UT",
					"type": "array",
					"maxItems": 2,
					"minItems": 0,
					"items": {
						"type": "object",
						"properties": {
							"personal_number": {
								"description": "ID-PERSNR - personal number",
								"type": "string",
								"maxLength": 10,
								"minLength": 10
							},
							"personal_number_century": {
								"description": "ID-PERSNR-SEKEL - personal number century",
								"type": "integer",
								"maximum": 99,
								"minimum": 0
							},
							"first_name": {
								"description": "BE-FNAMN - customer's first name",
								"type": "string",
								"maxLength": 15,
								"minLength": 15
							},
							"last_name": {
								"description": "BE-ENAMN - customer's last name",
								"type": "string",
								"maxLength": 27,
								"minLength": 27
							},
							"street_address": {
								"description": "AD-UTDELN - street address",
								"type": "string",
								"maxLength": 35,
								"minLength": 35
							},
							"zip_code": {
								"description": "ID-POSTNR - zip code",
								"type": "integer",
								"maximum": 99999,
								"minimum": 0
							},
							"postal_address": {
								"description": "AD-POSTSTN - postal address",
								"type": "string",
								"maxLength": 20,
								"minLength": 20
							},
							"reduced_income_amount": {
								"description": "BL-INK-REDUCERAD - reduced income amount",
								"type": "integer",
								"maximum": 999999999,
								"minimum": 0
							},
							"assignment_number_hash": {
								"description": "ID-ARENDE-HASH - assignment number hash",
								"type": "string",
								"maxLength": 70,
								"minLength": 70
							},
							"monthly_alimony": {
								"description": "BL-UNDERH-INK - monthly alimony",
								"type": "integer",
								"maximum": 999999,
								"minimum": 0
							},
							"child_expences": {
								"description": "BL-UNDERH-KOSTN - child expences",
								"type": "integer",
								"maximum": 999999,
								"minimum": 0
							},
							"amortization_means": {
								"description": "BE-AMORT - amortization means",
								"type": "string",
								"maxLength": 20,
								"minLength": 20
							}
						}
					}
				}
			}
		}
	}
}

Hi @misi01,

The issue is there with schema definition, I have fixed one snippet for you, try to fix others, referring to the below. Then it will work in swagger editor.

Error

{
	"name": "skuld_list",
	"in": "query",
	"description": "Contains up to 3 JPB172-SKULD",
	"type": "array",
	"maxItems": 3,
	"minItems": 0,
	"items": {
		"property": {
			"name": "code_type_of_loan",
			"description": "KD-SKULD - code type of loan",
			"required": true,
			"type": "string",
			"maxLength": 2,
			"minLength": 2
		},
		"property": {
			"name": "amount_current_debt",
			"description": "SU-SKULD - amount current debt",
			"required": true,
			"type": "integer",
			"maxLength": 99999999,
			"minLength": 0
		}
	}
}

Corrected:

{
	"name": "skuld_list",
	"in": "query",
	"description": "Contains up to 3 JPB172-SKULD",
	"type": "array",
	"maxItems": 3,
	"minItems": 0,
	"items": {
		"property": {
			"code_type_of_loan": {
				"description": "KD-SKULD - code type of loan",
				"required": true,
				"type": "string",
				"maxLength": 2,
				"minLength": 2
			},
			"amount_current_debt": {
				"description": "SU-SKULD - amount current debt",
				"required": true,
				"type": "integer",
				"maxLength": 99999999,
				"minLength": 0
			}
		}
	}
}

Hope this helps :slight_smile:

1 Like

DarkPhoenix. Many, many thanks for your help.

I would never have come up with that answer at all. Managed to change the Swagger based on your suggestion, and now at least it’s validating okay in JSON Validator. (Next thing is to get it to do the same in Postman and the Swagger editor. Hopefully though, your suggestion will solve those problems as well)

1 Like

Managed to get everything changed as DarkPhoenix recommended.
Pasted the Swagger file into JSON Validator - no errors.
Pasted it into Postman … and it failed pointing at the “paths” line

"paths": 
    {
        "/michael": 
        {
            "post": 
            {
                "tags": ["test-peter"],
                "summary": "",
                "description": "endpoint desc",
                "produces": ["application/json"],

with the following error message.

Should only have path names that start with /

Changing the setting to Open API 1.0 seemed to solve the problem.

1 Like

meenakshi. I’m trying to follow the instructions in the link you provided, but I’m afraid they don’t pass the “idiot test” (ie, are they idiot proof and anyone can follow them).
I’ve defined a new API and imported my Swagger file into it. Postman is happy with the layout. Trouble is, according to the instructions, I should then be able to click on the Generate Collection button, but it’s disabled.
What am I missing/doing wrong?

Hey @misi01,
Such a journey, I was following up on the issues with the schema. I’m glad you’re almost there. Would you like to share a screencast/gif?

I am not able to guess why that wouldn’t work :thinking:

Hey also, couldn’t help but read how you switched to OpenAPI 1.0, have you modified the version too in the api definition? Just wondering if it’s that

I’m assuming you don’t mean this ?

"swagger": "2.0",

Appreciate your taking the time. When you say

Would you like to share a screencast/gif?

do you mean that reply with a screen capture of my Postman scenario ?