Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

Parsing json getting error

(0) ShareShare
ReportReport
Posted on by 29

This is the json Im trying to parse. I required 3 field only from this Json (valid, businessNumberType,exemptionReason.Name) but Im getting the error The type of object cannot be set.

{
"@recordsetCount": 1,
"value": [
{
"id": 1,
"companyId": 1,
"customerCode": "0102AGTUR001",
"name": "Test Customer",
"attnName": "Vern Jorgensen",
"line1": "26516 Dineral",
"city": "Mission Viejo",
"postalCode": "92691",
"phoneNumber": "555-555-5555",
"faxNumber": "444-444-4444",
"emailAddress": "someone@gmail.com",
"contactName": "Vern Jorgensen",
"createdDate": "2019-06-13T22:48:48",
"modifiedDate": "2023-03-02T22:23:25.799417",
"country": "US",
"region": "CA",
"isBill": false,
"isShip": false,
"certificates": [
{
"id": 909,
"signedDate": "2016-02-01",
"expirationDate": "2020-12-31",
"filename": "50afc677-8632-4a21-9fe1-45dafb1bb664",
"documentExists": false,
"valid": true,
"verified": false,
"exemptPercentage": 0.0,
"isSingleCertificate": false,
"exemptionNumber": "Exempt-1234",
"validatedExemptionReason": {
"id": 19,
"name": "EXPOSURE: EXPIRED CERT"
},
"exemptionReason": {
"id": 70,
"name": "RESALE"
},
"status": "COMPLETE",
"createdDate": "2021-03-24T06:42:00",
"modifiedDate": "2021-03-24",
"taxNumberType": "FEIN",
"businessNumberType": "Business Services",
"pageCount": 0,
"exposureZone": {
"id": 89,
"name": "Washington",
"tag": "EZ_US_WA"
}
}
]


}
]
}

Runnable class

Class Test
{

Public static void main(Args _args)
{
//call the APi

output = streamRead.ReadToEnd();

TestJSONDataContract TestJSONDataContract = FormJsonSerializer::deserializeObject(classNum(TestJSONDataContract),output);// IineCont getting the error
}
}

My Contract classes

//TestJSONDataContract only one contract method
[DataContract]
Class TestJSONDataContract
{
[DataMemberAttribute('value'),DataCollectionAttribute(Types::class, classStr(JsonObjectDataContract))]
public List parmValue(List _value = value)
{
value = _value;
return value;
}
}

[DataContract]
Class JsonObjectDataContract
{
[DataMemberAttribute("certificates"),
DataCollectionAttribute(Types::Class, classStr(CustomerCertContract))]
public List parmCertificates(List _certificates = certificates)
{
certificates = _certificates;
return certificates;
}
}

[DataContract]
Class CustomerCertContract
{
[DataMember("valid")]
public boolean parmValid(boolean _valid = valid)
{
valid = _valid;
return valid;
}

[DataMember("businessNumberType")]
public str parmBusinessNumberType(str _businessNumberType = businessNumberType)
{
businessNumberType = _businessNumberType;
return businessNumberType;
}
}

Please help me where I am going wrong

  • Vishnu@94 Profile Picture
    29 on at
    RE: Parsing json getting error

    I got the solution Thanks martin

  • Martin Dráb Profile Picture
    232,996 Most Valuable Professional on at
    RE: Parsing json getting error

    Your code still lacks line indentation. It should look like this:

    {
      "@recordsetCount": 1,
      "value": [
        {
          "id": 1,
          "companyId": 1,
          "customerCode": "0102AGTUR001",
          "name": "Test Customer",
          "attnName": "Vern Jorgensen",
          "line1": "26516 Dineral",
          "city": "Mission Viejo",
          "postalCode": "92691",
          "phoneNumber": "555-555-5555",
          "faxNumber": "444-444-4444",
          "emailAddress": "someone@gmail.com",
          "contactName": "Vern Jorgensen",
          "createdDate": "2019-06-13T22:48:48",
          "modifiedDate": "2023-03-02T22:23:25.799417",
          "country": "US",
          "region": "CA",
          "isBill": false,
          "isShip": false,
          "certificates": [
            {
              "id": 909,
              "signedDate": "2016-02-01",
              "expirationDate": "2020-12-31",
              "filename": "50afc677-8632-4a21-9fe1-45dafb1bb664",
              "documentExists": false,
              "valid": true,
              "verified": false,
              "exemptPercentage": 0,
              "isSingleCertificate": false,
              "exemptionNumber": "Exempt-1234",
              "validatedExemptionReason": {
                "id": 19,
                "name": "EXPOSURE: EXPIRED CERT"
              },
              "exemptionReason": {
                "id": 70,
                "name": "RESALE"
              },
              "status": "COMPLETE",
              "createdDate": "2021-03-24T06:42:00",
              "modifiedDate": "2021-03-24",
              "taxNumberType": "FEIN",
              "businessNumberType": "Business Services",
              "pageCount": 0,
              "exposureZone": {
                "id": 89,
                "name": "Washington",
                "tag": "EZ_US_WA"
              }
            }
          ]
        }
      ]
    }

    (I used json-indent.com to fix indentation.)

    class Test
    {
    	public static void main(Args _args)
    	{
    		//call the APi
    
    		output = streamRead.ReadToEnd();
    
    		TestJSONDataContract testJSONDataContract = FormJsonSerializer::deserializeObject(classNum(TestJSONDataContract), output);// IineCont getting the error
    	}
    }
    
    //Contract class
    [DataContract]
    class TestJSONDataContract
    {
    	[	DataMemberAttribute('value'),
    		DataCollectionAttribute(Types::class, classStr(JsonObjectDataContract))]
    	public List parmValue(List _value = value)
    	{
    		value = _value;
    		return value;
    	}
    }
    
    [DataContract]
    class JsonObjectDataContract
    {
    	[	DataMemberAttribute("certificates"),
    		DataCollectionAttribute(Types::Class, classStr(CustomerCertContract))]
    	public List parmCertificates(List _certificates = certificates)
    	{
    		certificates = _certificates;
    		return certificates;	
    	}
    }
    
    class CustomerCertContract
    {
    	[DataMember("valid")]
    	public boolean parmValid(boolean _valid = valid)
    	{
    		valid = _valid;
    		return valid;
    	}
    
    	[DataMember("businessNumberType")]
    	public str parmBusinessNumberType(str _businessNumberType = businessNumberType)
    	{
    		businessNumberType = _businessNumberType;
    		return businessNumberType;
    	}
    }

    Won't you get more details about the problem if you debug FormJsonSerializer?

    Please tell us which version of AX you're using. It seems that it's either AX 2012 (and we need to update the version tag), or it's actually about F&O (and I'll move it to Dynamics 365 Finance Forum).

  • Vishnu@94 Profile Picture
    29 on at
    RE: Parsing json getting error

    MuthukumaranAX  I tried the above way but still Im getting the error.

  • Vishnu@94 Profile Picture
    29 on at
    RE: Parsing json getting error

    Hi Martin I have formatted the code now Could you please have a look into that. Is it required to put all the fields in the JSON to the contract class.

  • Vishnu@94 Profile Picture
    29 on at
    RE: Parsing json getting error

    Class Test
    {
    
    public static void main(Args _args)
    {
    //call the APi
    
    output = streamRead.ReadToEnd();
    
    TestJSONDataContract TestJSONDataContract = FormJsonSerializer::deserializeObject(classNum(TestJSONDataContract),output);// IineCont getting the error
    }
    }
    
    //Contract class
    [DataContract]
    Class TestJSONDataContract
    {
    [DataMemberAttribute('value'),DataCollectionAttribute(Types::class, classStr(JsonObjectDataContract))]
    public List parmValue(List _value = value)
    {
    value = _value;
    return value;
    }
    }

    Class CustomerCertContract
    {
    [DataMember("valid")]
    public boolean parmValid(boolean _valid = valid)
    {
    valid = _valid;
    return valid;
    }
    
    [DataMember("businessNumberType")]
    public str parmBusinessNumberType(str _businessNumberType = businessNumberType)
    {
    businessNumberType = _businessNumberType;
    return businessNumberType;
    }
    }

  • MuthukumaranAX Profile Picture
    2,901 on at
    RE: Parsing json getting error

    You can check the below link, might help to resolve the issue

    allaboutdynamic.com/.../

  • Martin Dráb Profile Picture
    232,996 Most Valuable Professional on at
    RE: Parsing json getting error

    Could you please paste code with indentation (through Insert > Code) and mention your version of AX?

    Line indentation makes code much easier to follow. You can even enable syntax highlighting for JSON (not X++, unfortunately).

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

🌸 Community Spring Festival 2025 Challenge 🌸

WIN Power Platform Community Conference 2025 tickets!

Jonas ”Jones” Melgaard – Community Spotlight

We are honored to recognize Jonas "Jones" Melgaard as our April 2025…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 294,261 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 232,996 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,158 Moderator

Leaderboard

Product updates

Dynamics 365 release plans