0

Having an Issue with a JSON request. I'm getting an "The remote server returned an error: (422) Unprocessable Entity." Error returned. I've gone line by line through the API user Guide and have only found one anomaly. I don't know if this would cause the error.

Here is the complete JSON statement:

{"service":{"level":"STD"},"payment":{"terms":"Prepaid","payer":"Third Party"},"transit":{"pickupDate":"20230728"},"commodities":[{"classification":"60","weight":"2600","length":"42","width":"42","height":"45","pieces":"2","packageingType":"PAT","description":"USED BOOKS","stackable":"Y"}],"origin":{"account":"","city":"Knoxville","stateProvince":"TN","postalCode":"37918","country":"USA"},"destination":{"account":"","city":"Atlanta","stateProvince":"GA","postalCode":"30306","country":null},"billTo":{"account":"0627227","name":"FMS","address":"3517 Neil Dr","city":"Knoxvile","stateProvince":"TN","postalCode":"37918","country":"USA"}}

*****Below is the user guide example for the commodities; enter image description here

**** Here's what I'm sending in:

enter image description here

There seems to be (in what I'm sending in) a linefeed after the word "commodities": [ {

as the API example shows ""commodities" : [ {" No line feed between the "[" & "{ ".

**** The Magic Questions *** Would that line feed cause the error and most important how do I get rid of it? I'm very new with JSON and work solo so any help would be greatly appreciated.

Dim Load As New fgtload

    Dim Item1 As New items

    With Item1
        .classification = ("60")
        .weight = ("2600")
        .length = ("42")
        .width = ("42")
        .height = ("45")
        .pieces = ("2")
        .packageingType = ("PAT")
        .description = ("USED BOOKS")
        .stackable = ("Y")
    End With



    Load.commodities.Add(Item1)


Public Class fgtload 'Primary wrapper
    Public service As New fgtservice
    Public payment As New fgtpayment
    Public transit As New fgttransit
    Public commodities As New List(Of Items)
    Public origin As New fgtorigin
    Public destination As New fgtdestination
    Public billTo As New fgtbillto
End Class

Public Class Items
    Public classification As String 'class  required
    Public weight As String '7max  lbs required
    Public length As String '3max required
    Public width As String '3max required
    Public height As String '3 max required
    Public pieces As String ' 5 max required
    Public packageingType As String 'required  PAT for Pallet , LSE for Loose
    Public description As String 'required
    Public stackable As String 'required
End Class
dashley
  • 66
  • 6
  • 1
    Both JSON sections, as presented here, are invalid. The first one is cut out from a larger JSON, the second one *appears* to be incomplete, but it's not clear whether it's the *whole thing* -- You have to post the complete JSON you're sending and as text, never post images of code / stack traces / XML / JSON / whatever that others may need for testing / validation -- Also post the code that serializes those classes -- Line feeds are irrelevant, unless what appears to be a *line feed* is generated by special characters that cause the JSON validation to fail – Jimi Jul 26 '23 at 15:38
  • 1
    Might you please [edit] your question to include your JSON as **text** rather than as screenshots? On stack overflow images should not be used for textual content, see [*Why should I not upload images of code/data/errors?*](https://meta.stackoverflow.com/a/285557) for why. A [mcve] showing what you have tried that did not work would maximize your chances of getting help. See [ask]. – dbc Jul 26 '23 at 19:37
  • 1
    As far as the whitespace goes, according to the [original JSON proposal](https://www.json.org/) as well as [RFC 8259](https://www.rfc-editor.org/rfc/rfc8259): ***Whitespace can be inserted between any pair of tokens.***. So the presence or absence of a linefeed outside of a string literal shouldn't matter (unless the receiving system has broken JSON parsing). – dbc Jul 26 '23 at 19:40
  • [400 vs 422 response to POST of data](https://stackoverflow.com/a/20215807) suggests that 422 should be used for well-formed but semantically invalid JSON, so chances are your error is that the remote service is rejecting the values you are sending for some reason -- but we have no way of guessing what that reason might be because you haven't told us about the service or what JSON it expects. – dbc Jul 26 '23 at 19:44
  • I'm not that familiar with JSON, but as a programmer I know brackets always come in pairs and your example seems to lack a closing "]" – Hel O'Ween Jul 27 '23 at 07:52

0 Answers0