This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC3220SF: AWS JSON token count definition

Part Number: CC3220SF


Hi,

I saw a few threads where the issues were caused by the following parameter being set to a wrong value:

#define MAX_JSON_TOKEN_EXPECTED 120 ///< These are the max tokens that is expected to be in the Shadow JSON document. Include the metadata that gets published

Usually the advice was just to increase the value and it seemed to have worked. In that regards, I would like to understand the definition of "MAX JSON TOKEN". What is it exactly, how to calculate it? What exactly is considered the "TOKEN" in the AWS Shadow JSON? Is it JSON Key? Is it JSON value? Is it Key-Value pair?

Thanks.

David

  • Hi David,

    The MAX_JSON_TOKEN_EXPECTED refers to the number of JSON objects in the shadow state string passed to and from AWS IoT. See the documentation of the JSMN library for an explanation of what is considered a JSON token by the library: https://zserge.com/jsmn.html

    Do note that for the number of JSON tokens used may be much higher than expected. This is since there is some metadata with timestamps and such included in the shadow updates that are handled for you automatically by the AWS SDK, but nonetheless consume JSON resources. If you take a look at the shadow document of your thing on AWS, you'll see the full extent of the JSON shadow data that is kept for your device.

    Let me know if you need more clarification or have further questions on this topic.

    Regards,

    Michael

  • Hi Michael,

    Great link, thanks.

    "The MAX_JSON_TOKEN_EXPECTED refers to the number of JSON objects in the shadow state string passed to and from AWS IoT"

    Can you clarify if MAX_JSON_TOKEN_EXPECTED  must be equal to the number of OBJECTS or to the number of TOKENS?

    For the example below, what  is  the correct MAX_JSON_TOKEN_EXPECTED  ?

    '{ "name" : "Jack", "age" : 27 }'


    Thanks.
    David
  • Hi David,

    The expected number of tokens in that string is 3, as there are two JSON strings enclosed in one JSON object.

    You can take a look at the implementation of jsmn_parse() in jsmn.c and work through the logic if you are still unsure about how the parser will parse that JSON example.

    Regards,

    Michael