ndarkness
ndarkness

Reputation: 1089

Is this json file well parsed?

I would like to know if the following message is well parsed according to json format, I think it is but the application that needs to process it complains about it with the following error

[ERR]tx data JSON file error

The code in the file is this one

{"tx":
{
    "moteeui":"fa789f0000000000",
    "txmsgid":"000000000152",
    "trycount":"5",
    "txsynch" : "false",
    "ackreq" : "true",
    "userdata":
    {
        "port":"10",
        "payload":"ABCABC"
    }
}
}

Thanks in advance,

regards!

I have tried also the following snippet

[{
    "mote": "202020",
    "payload": "ABCB",
    "port": 2,
    "trycount": 5,
    "txmsgid": ""
}]

I have validated with JSONLint and I get an error saying

[ERR]tx data JSON parsing error: 3 object item(s) left unpacked

Does it ring a bell?

Thanks again

Upvotes: 0

Views: 42

Answers (1)

mikeyq6
mikeyq6

Reputation: 1148

Yes, it is correct.

For your info, JSONLint is a good site for checking the validity of JSON.

However, you may want to rethink setting numeric values as strings. ie, it is a better idea to say:

"trycount":5

rather than

"trycount":"5"

As the former indicates to whatever application is consuming the JSON that the value should be parsed as a number.

Similarly with the boolean values, it's better practise to use:

"txsynch" : false

rather than

"txsynch" : "false"

It won't cause an error in your JSON parser to pass these as strings, it is just better practise.

The error in the parser could be for many different reasons.

Upvotes: 1

Related Questions