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.

CC3220: JSON template create error

Part Number: CC3220


Hi I am trying to do JSON construct by taking the JSON app in SDK as reference and getting error codes Please find below calling and attached source

/*
 * Copyright (c) 2015-2017, Texas Instruments Incorporated
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * *  Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *
 * *  Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * *  Neither the name of Texas Instruments Incorporated nor the names of
 *    its contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 *  ======== httpget.c ========
 *  HTTP Client GET example application
 */

/* BSD support */
#include "string.h"
#include <ti/display/Display.h>
#include <ti/net/http/httpclient.h>
#include "semaphore.h"

#define HOSTNAME              "http://www.example.com"
#define REQUEST_URI           "/"
#define USER_AGENT            "HTTPClient (ARM; TI-RTOS)"
#define HTTP_MIN_RECV         (256)

extern Display_Handle display;
extern sem_t ipEventSyncObj;
extern void printError(char *errString,
                       int code);

/*
 *  ======== httpTask ========
 *  Makes a HTTP GET request
 */
void* httpTask(void* pvParameters)
{
    bool moreDataFlag = false;
    char data[HTTP_MIN_RECV];
    int16_t ret = 0;
    int16_t len = 0;

    Display_printf(display, 0, 0, "Sending a HTTP GET request to '%s'\n",
                   HOSTNAME);

    HTTPClient_Handle httpClientHandle;
    int16_t statusCode;
    httpClientHandle = HTTPClient_create(&statusCode,0);
    if(statusCode < 0)
    {
        printError("httpTask: creation of http client handle failed",
                   statusCode);
    }

    ret =
        HTTPClient_setHeader(httpClientHandle,
                             HTTPClient_HFIELD_REQ_USER_AGENT,
                             USER_AGENT,strlen(USER_AGENT),
                             HTTPClient_HFIELD_PERSISTENT);
    if(ret < 0)
    {
        printError("httpTask: setting request header failed", ret);
    }

    ret = HTTPClient_connect(httpClientHandle,HOSTNAME,0,0);
    if(ret < 0)
    {
        printError("httpTask: connect failed", ret);
    }
    ret =
        HTTPClient_sendRequest(httpClientHandle,HTTP_METHOD_GET,REQUEST_URI,
                               NULL,0,
                               0);
    if(ret < 0)
    {
        printError("httpTask: send failed", ret);
    }

    if(ret != HTTP_SC_OK)
    {
        printError("httpTask: cannot get status", ret);
    }

    Display_printf(display, 0, 0, "HTTP Response Status Code: %d\n", ret);

    len = 0;
    do
    {
        ret = HTTPClient_readResponseBody(httpClientHandle, data, sizeof(data),
                                          &moreDataFlag);
        if(ret < 0)
        {
            printError("httpTask: response body processing failed", ret);
        }
        Display_printf(display, 0, 0, "%.*s \r\n",ret,data);
        len += ret;
    }
    while(moreDataFlag);

    Display_printf(display, 0, 0, "Received %d bytes of payload\n", len);

    ret = HTTPClient_disconnect(httpClientHandle);
    if(ret < 0)
    {
        printError("httpTask: disconnect failed", ret);
    }

    HTTPClient_destroy(httpClientHandle);
    return(0);
}

Display_printf(display, 0, 0, "JSON Start \n");

createTemplate();

createObject();

setValue();

build();

Display_printf(display, 0, 0, "JSON End \n");

Results:

JSON Start

Json_createTemplate = -102

Json_createObject = -301

Json_setValue = -302

Json_build = -302

JSON End

For the same if any other way is also good.

Thank you

  • Hi Raghunandana DS,

    -102 means parsing failure (see "json_engine.h")
    What is the string that you are trying to parse?

    Br,
    Kobi
  • Hi Kobi,

    Please find this attach,

    /*
     * JSON.c
     *
     *  Created on: 22-Oct-2018
     *      Author: Raghunandana.S
     */
    
    //*******************************************************
    //                  INCLUDES
    //*******************************************************
    /* Standard includes */
    #include <stdarg.h>
    #include <unistd.h>
    
    /* TI-DRIVERS Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/SPI.h>
    #include <ti/drivers/UART.h>
    #include <ti/drivers/Power.h>
    #include <ti/drivers/net/wifi/simplelink.h>
    
    #include <ti/utils/json/json.h>
    //#include "uart_term.h"
    #include "pthread.h"
    
    #include <JSONtest.h>
    #include <ti/display/Display.h>
    extern Display_Handle display;
    
    
    //*******************************************************
    //                  DEFINES - CONSTS
    //*******************************************************
    #define APPLICATION_NAME                        "JSON"
    #define APPLICATION_VERSION                     "1.0.0"
    #define SL_STOP_TIMEOUT                         (200)
    #define SPAWN_TASK_PRIORITY                     (9)
    #define TASKSTACKSIZE                           (4096)
    #define TEMPLATE_FILENAME                       "template1"
    #define JSON_FILENAME                           "json1"
    
    #define ASCI_0                                  48
    #define ASCI_9                                  57
    #define OBJ_BUFFER_SIZE                         6
    #define CMD_BUFFER_SIZE                         100
    #define SELECT_BUFFER_SIZE                      2
    //*******************************************************
    //                  STRUCTs
    //*******************************************************
    
    typedef struct
    {
        char *fileBuffer;
    } Json_Filename_t;
    
    typedef enum
    {
        JSON_CREATE_TEMPLATE = 0,
        JSON_CREATE_OBJECT = 1,
        JSON_PARSE = 2,
        JSON_GET_VALUE = 3,
        JSON_SET_VALUE = 4,
        JSON_GET_ARRAY_MEMBER_COUNT = 5,
        JSON_BUILD = 6,
        JSON_DESTROY_TEMPLATE = 7,
        JSON_DESTROY_JSON_OBJECT = 8
    }json_action;
    
    typedef enum
    {
        INT32 = 0,
        STRING_RAW = 1,
        BOOLEAN = 2
    }json_value_t;
    //*******************************************************
    //                     GLOBAL VARIABLES
    //*******************************************************
    Json_Handle templateHandle;
    Json_Handle jsonObjHandle;
    Json_Filename_t templateBuff;
    Json_Filename_t jsonBuffer;
    int16_t templateSize;
    uint16_t objSize;
    
    //*******************************************************
    //                      LOCAL FUNCTION PROTOTYPES
    //*******************************************************
    int16_t readFile(Json_Filename_t  * pBufferFile,
                     char *FileName);
    
    
    
    
    //*****************************************************************************
    //
    //! \brief This function reads a file from the file system and stores it
    //!        in a buffer.
    //! \param[out]    pBufferFile - pointer to a buffer which will be filled with
    //!  a file
    //! \param[in]     FileName    - pointer to filename which needs to be
    //!                              read.
    //!
    //! \return on success number of bytes read from file system
    //!         on failure error code.
    //****************************************************************************
    int16_t readFile(Json_Filename_t *pBufferFile,
                     char *FileName)
    {
        int32_t FileHdl = 0;
        int32_t Status = 0;
        SlFsFileInfo_t *FsFileInfo;
        uint32_t FileSize;
        int16_t retVal = 0;
    
        FsFileInfo = malloc(sizeof(SlFsFileInfo_t));
    
        if(FsFileInfo)
        {
            /* Get the file size */
            Status = sl_FsGetInfo((unsigned char *)FileName,0,FsFileInfo);
            if(Status < 0)
            {
    //            UART_PRINT("FS - Couldn't get info on file. error status %d \n\r",
    //                       Status);
                return(Status);
            }
            FileSize = FsFileInfo->Len;
            free(FsFileInfo);
    
            FileHdl = sl_FsOpen((unsigned char *)FileName, SL_FS_READ,0);
            if(FileHdl < 0)
            {
    //           UART_PRINT("FS - Couldn't open file. error status %d \n\r",FileHdl);
               return(FileHdl);
            }
            else
            {
                pBufferFile->fileBuffer = malloc(FileSize + 1);
                if(pBufferFile->fileBuffer != NULL)
                {
                    memset(pBufferFile->fileBuffer,'\0',FileSize + 1);
                    /* Read the entire file */
                    Status =
                        sl_FsRead(FileHdl, 0,
                                  (unsigned char *)pBufferFile->fileBuffer,
                                  FileSize);
                    if(Status < 0)
                    {
    //                    UART_PRINT("FS - Couldn't read file. error status %d \n\r",
    //                               Status);
                        return(Status);
                    }
                    retVal = sl_FsClose(FileHdl,NULL,NULL,0);
                    if(retVal < 0)
                    {
    //                   UART_PRINT("FS - Couldn't close file. error status %d \n\r",
    //                               retVal);
                        return(retVal);
                    }
                    return(Status);
                }
                else
                {
    //                UART_PRINT("Couldn't allocate memory \n\r");
                    return(JSON_RC__MEMORY_ALLOCATION_ERROR);
                }
            }
        }
        else
        {
    //        UART_PRINT("Couldn't allocate memory \n\r");
            return(JSON_RC__MEMORY_ALLOCATION_ERROR);
        }
    }
    
    //*****************************************************************************
    //
    //! \brief This function removes from the buffer '\n' and ' '
    //!
    //! \param[inout]      pBuf pointer to a buffer
    //!
    //! \return none
    //****************************************************************************
    void removeUnwantedChars(char *pBuf)
    {
        char * str_tmp;
        uint16_t i = 0,j = 0;
        str_tmp = pBuf;
    
        for(i = 0; str_tmp[i] != '\0'; ++i)
        {
            while((!(str_tmp[i] != '\n') ||
                   !(str_tmp[i] != ' '))&& (str_tmp[i] != '\0'))
            {
                for(j = i; str_tmp[j] != '\0'; ++j)
                {
                    str_tmp[j] = str_tmp[j + 1];
                }
                str_tmp[j] = '\0';
            }
        }
    }
    
    //*****************************************************************************
    //
    //! \brief This function validates and changes the Json text into readable
    //!        Json convention
    //! \param[inout]      pBuf pointer to a buffer
    //!
    //! \return none
    //****************************************************************************
    void validateForPrint(char *pBuf)
    {
        char * str_tmp = pBuf;
        char * pre = NULL;
        uint16_t i = 0,j = 0;
        int16_t ident = 0;
    
        for(i = 0; str_tmp[i] != '\0'; ++i)
        {
            if((str_tmp[i] == ']')|| (str_tmp[i] == '}'))
            {
                ident--;
            }
            if(pre != NULL)
            {
                if((*pre == '[')|| (*pre == '{')|| (*pre == ',')||
                   (str_tmp[i] == ']')||(str_tmp[i] == '}'))
                {
    //                UART_PRINT("\n\r");
                    for(j = 0; j < ident; j++)
                    {
    //                    UART_PRINT(" ");
                    }
                }
            }
    //        UART_PRINT("%c",str_tmp[i]);
            if((str_tmp[i] == '[')||(str_tmp[i] == '{'))
            {
                ident++;
            }
            pre = &str_tmp[i];
        }
    }
    
    void createTemplate(void)
    {
        int16_t retVal;
        templateBuff.fileBuffer = "test";
        retVal = Json_createTemplate(&templateHandle,
                                      templateBuff.fileBuffer,
                                      templateSize);
    
        Display_printf(display, 0, 0, "Json_createTemplate = %d \n", retVal);
    }
    
    void createObject(void)
    {
        int16_t retVal;
        /* convert object size received from uart into integer */
        objSize = 32;   //  atoi(objSizeBuffer);
        retVal = Json_createObject(&jsonObjHandle,templateHandle,objSize);
        Display_printf(display, 0, 0, "Json_createObject = %d \n", retVal);
    }
    
    void parse(void)
    {
        int16_t retVal;
    
        retVal =
            Json_parse(jsonObjHandle,jsonBuffer.fileBuffer,
                       strlen(jsonBuffer.fileBuffer));
    }
    
    void getValue(void)
    {
        char getBuffer[CMD_BUFFER_SIZE];
        char keyBuffer[CMD_BUFFER_SIZE];
        char valueType[SELECT_BUFFER_SIZE];
        uint16_t valueSize = CMD_BUFFER_SIZE;
        int16_t retVal;
        int32_t numValue;
        /* initialize key and set buffers to null terminated chars */
        memset(keyBuffer,'\0',CMD_BUFFER_SIZE);
        memset(getBuffer,'\0',CMD_BUFFER_SIZE);
    
    
    //    UART_PRINT("\n");
    //    UART_PRINT("Processing the request ... \n\r");
        if(atoi(valueType) == INT32)
        {
            retVal = Json_getValue(jsonObjHandle,keyBuffer,&numValue,&valueSize);
            if(retVal == JSON_RC__VALUE_IS_NULL)
            {
    //            UART_PRINT("The value is null\n\r");
                return;
            }
            else if(retVal < 0)
            {
    //            UART_PRINT("Error: %d  , Couldn't get the data \n\r",retVal);
                return;
            }
    //        UART_PRINT("The value is : %d \n\r",numValue);
        }
        else if(atoi(valueType) == STRING_RAW)
        {
            retVal = Json_getValue(jsonObjHandle,keyBuffer,getBuffer,&valueSize);
            if(retVal == JSON_RC__VALUE_IS_NULL)
            {
    //            UART_PRINT("The value is null\n\r");
                return;
            }
            else if(retVal < 0)
            {
    //            UART_PRINT("Error: %d  , Couldn't get the data \n\r",retVal);
                return;
            }
    //        UART_PRINT("The value is : %s \n\r",getBuffer);
        }
        else if(atoi(valueType) == BOOLEAN)
        {
            retVal = Json_getValue(jsonObjHandle,keyBuffer,&numValue,&valueSize);
            if(retVal == JSON_RC__VALUE_IS_NULL)
            {
    //            UART_PRINT("The value is null\n\r");
                return;
            }
            else if(retVal < 0)
            {
    //            UART_PRINT("Error: %d  , Couldn't get the data \n\r",retVal);
                return;
            }
    //        UART_PRINT("The value is : %s \n\r",
    //                   ((uint8_t)numValue == 0) ? "false" : "true");
        }
        else
        {
    //        UART_PRINT("Invalid value type.\n\r");
        }
    }
    
    void setValue(void)
    {
        char setBuffer[CMD_BUFFER_SIZE] = "nec";
        char keyBuffer[CMD_BUFFER_SIZE] = "name";
    //    char valueType[SELECT_BUFFER_SIZE];
        uint16_t valueSize = CMD_BUFFER_SIZE;
        int16_t retVal;
    //    int32_t numValue;
        /* initialize key and set buffers to null terminated chars */
        memset(keyBuffer,'\0',100);
        memset(setBuffer,'\0',100);
    
        char* key = "name";
        char* value = "nec";
    
    //    strcpy(keyBuffer, key);
    //    strcpy(setBuffer, value);
    //    keyBuffer = &key;
    //    setBuffer = &value;
            valueSize = strlen(setBuffer);
            retVal = Json_setValue(jsonObjHandle, keyBuffer,setBuffer,valueSize);
            Display_printf(display, 0, 0, "Json_setValue = %d \n", retVal);
    
    
    }
    
    void getArrayMemberCount(void)
    {
        char keyBuffer[CMD_BUFFER_SIZE];
        int16_t retVal;
        /* Initialize the key buffer to null terminated chars */
        memset(keyBuffer,'\0',CMD_BUFFER_SIZE);
        retVal = GetCmd((char *)keyBuffer, CMD_BUFFER_SIZE);
        if(retVal <= 0)
        {
    //        UART_PRINT("Buffer length exceeded\n\r");
            return;
        }
        retVal = Json_getArrayMembersCount(jsonObjHandle,keyBuffer);
        if(retVal < 0)
        {
    //        UART_PRINT("Error: %d  , Couldn't get array member count.  \n\r",
    //                   retVal);
            return;
        }
    
    //    UART_PRINT("Number of members in array %d \r\n",retVal);
    }
    
    void build(void)
    {
        char        *builtText;
        int16_t retVal;
        uint16_t builtTextSize;
        /* set object size to default size if zero was chosen */
        builtTextSize = (objSize == 0) ? JSON_DEFAULT_SIZE : objSize;
        /* creates buffer for building the json */
        builtText = (char *)malloc(builtTextSize);
        if(builtText)
        {
            retVal = Json_build(jsonObjHandle,builtText,&builtTextSize);
            if(retVal < 0)
            {
                Display_printf(display, 0, 0, "Json_build = %d \n", retVal);
    //            UART_PRINT("Error: %d  , Couldn't build the json.  \n\r", retVal);
                free(builtText);
                return;
            }
            removeUnwantedChars(builtText);
            /* prints json according to json convention */
            validateForPrint(builtText);
            free(builtText);
        }
        else
        {
    //        UART_PRINT("Couldn't allocate memory \n\r");
        }
    }
    
    void destroyTemplate(void)
    {
        int16_t retVal;
    
        retVal = Json_destroyTemplate(templateHandle);
        if(retVal < 0)
        {
    //       UART_PRINT("Error: %d  , Couldn't destroy the template.  \n\r", retVal);
           return;
        }
    //    UART_PRINT("Template was destroyed successfully.  \n\r", retVal);
    }
    
    void destroyJsonObject(void)
    {
        int16_t retVal;
    
        retVal = Json_destroyObject(jsonObjHandle);
        if(retVal < 0)
        {
    //        UART_PRINT("Error: %d  , Couldn't destroy the json.  \n\r", retVal);
            return;
        }
    //    UART_PRINT("Json was destroyed successfully.  \n\r", retVal);
    }
    

    Sorry for wrong attach in the first post.

    Thank you

  • Hi,

    The template buffer you provide ("test" in createTemplate) doesn't comply with the JSON library expectation. See documentation of Json_createTemplate (e.g. in the header file).

    Br,
    Kobi
  • Hi Kobi,
    Thanks for the write suggestion, I am getting success code find below lines of code:
    char *templatestr = "{"
    "\"Temperature\":int32,"
    "\"Humidity\":int32,"
    "\"Celsius\":int32,"
    "\"Farenheit\":int32,"
    "\"MacId\":string}";
    templateSize = strlen(templatestr);
    Display_printf(display, 0, 0, "str size = %d \n", strlen(templatestr));
    retVal = Json_createTemplate(&templateHandle,
    templatestr,
    templateSize);

    The template is creating, as well object also creating.
    How to do for the float values, I replaced int32 in above with float. The Json_createTemplate returns -102 again.
    eg:
    char *templatestr = "{"
    "\"Temperature\":float,"
    "\"Humidity\":int32,"
    "\"Celsius\":int32,"
    "\"Farenheit\":int32,"
    "\"MacId\":string}";
    templateSize = strlen(templatestr);
    Display_printf(display, 0, 0, "str size = %d \n", strlen(templatestr));
    retVal = Json_createTemplate(&templateHandle,
    templatestr,
    templateSize);
    Thanks
  • Hi Raghunandana DS,

    "float" is not supported.

    Please refer to the following table (from parse_common.c) for the valid types:

    static const string_dictionary_T gPropertyTypeSpecifier[] =
    {
    { LITERAL_STRING_AND_LEN ("int32" ) , PROPERTY_TYPE__INT32 } ,
    { LITERAL_STRING_AND_LEN ("uint32" ) , PROPERTY_TYPE__UINT32 } ,
    { LITERAL_STRING_AND_LEN ("string" ) , PROPERTY_TYPE__STRING } ,
    { LITERAL_STRING_AND_LEN ("raw" ) , PROPERTY_TYPE__RAW } ,
    { LITERAL_STRING_AND_LEN ("boolean") , PROPERTY_TYPE__BOOLEAN } ,
    { LITERAL_STRING_AND_LEN ("real32" ) , PROPERTY_TYPE__REAL32__BASE } ,
    { LITERAL_STRING_AND_LEN ("ureal32") , PROPERTY_TYPE__UREAL32__BASE} ,
    { DICTIONARY_DEFAULT_AT_END , 0 , PROPERTY_TYPE__UNKNOWN }
    } ;

    You can try using the "real32" - although i couldn't find any example of how to use it.
    We'll add the missing documentation in one of the coming SDK releases.

    A simpler option would be to use integers (as mantissa and exponent).

    Br,
    Kobi
  • Hi Kobi,

    I am getting -202 parse error, can you pls look it why?

    Json_parse(jsonObjHandle,data,

                      strlen(data));

    where :

    data={"Duration":2} ,  is http get response of  httpTask(); in http get example of SDK. Nothing is changed in the code here. I get {"Duration":2} in UART print.

    Json_parse is returning -200 for the above.

    The same I have tried by making data as macro and is returning '0'successfully.

    Example:

    #define NEWDATA {"Duration":2}

    Json_parse(jsonObjHandle,NEWDATA ,

                      strlen(NEWDATA )); // this is returning '0'

    My server is responding JSON only, can I know what is wrong here?

    For more info see code below:


    bool moreDataFlag = false; char data[HTTP_MIN_RECV]; int16_t ret = 0; int16_t len = 0; Display_printf(display, 0, 0, "Sending a HTTP GET request to '%s'\n", HOSTNAME); HTTPClient_Handle httpClientHandle; int16_t statusCode; httpClientHandle = HTTPClient_create(&statusCode,0); if(statusCode < 0) { printError("httpTask: creation of http client handle failed", statusCode); } ret = HTTPClient_setHeader(httpClientHandle, HTTPClient_HFIELD_REQ_USER_AGENT, USER_AGENT,strlen(USER_AGENT), HTTPClient_HFIELD_PERSISTENT); if(ret < 0) { printError("httpTask: setting request header failed", ret); } ret = HTTPClient_connect(httpClientHandle,HOSTNAME,0,0); if(ret < 0) { printError("httpTask: connect failed", ret); } ret = HTTPClient_sendRequest(httpClientHandle,HTTP_METHOD_GET,REQUEST_GET_URI, NULL,0, 0); if(ret < 0) { printError("httpTask: send failed", ret); } if(ret != HTTP_SC_OK) { printError("httpTask: cannot get status", ret); } Display_printf(display, 0, 0, "HTTP Response Status Code: %d\n", ret); len = 0; do { ret = HTTPClient_readResponseBody(httpClientHandle, data, sizeof(data), &moreDataFlag); if(ret < 0) { printError("httpTask: response body processing failed", ret); } Display_printf(display, 0, 0, "%.*s \r\n",ret,data); strcpy(builtBuff, data); // JSON Parse Start // createHttpGetTemplate(); createHttpGetObject(); parseHttpGet(data); getValueHttpGet(); // JSON Parse End // len += ret; } while(moreDataFlag); Display_printf(display, 0, 0, "Received %d bytes of payload\n", len); ret = HTTPClient_disconnect(httpClientHandle); if(ret < 0) { printError("httpTask: disconnect failed", ret); } HTTPClient_destroy(httpClientHandle); return(0);

    for the json parsing, find below

    void createHttpGetTemplate(void)
    {
        int16_t retVal;
        char *templatestr = "{"
                "\"Duration\":int32}";
        templateSize = strlen(templatestr);
        Display_printf(display, 0, 0, "str size = %d \n", strlen(templatestr));
        retVal = Json_createTemplate(&templateHandle,
                                     templatestr,
                                      templateSize);
    
        Display_printf(display, 0, 0, "Json_createTemplate = %d \n", retVal);
    }
    
    void createHttpGetObject(void)
    {
        int16_t retVal;
        /* convert object size received from uart into integer */
        objSize = 1024;   //  atoi(objSizeBuffer);
        retVal = Json_createObject(&jsonObjHandle,templateHandle,objSize);
        Display_printf(display, 0, 0, "Json_createObject = %d \n", retVal);
    }
    
    
    
    void parseHttpGet(char *buf)
    {
        int16_t retVal;
    
        retVal =
            Json_parse(jsonObjHandle,buf,
                       strlen(buf));
        Display_printf(display, 0, 0, "Json_parse = %d \n", retVal);
    }
    
    
    
    void getValueHttpGet(void)
    {
        int16_t retVal;
        char *key =  "\"Duration\"";
        uint32_t   value;
        uint16_t valueSize = 4;
        retVal = Json_getValue(jsonObjHandle,key,&value,&valueSize);
        Display_printf(display, 0, 0, "Json_getValue = %d \n", retVal);
        Display_printf(display, 0, 0, "Received Duration = %d \n", value);
    
    
    }

    And one thing in the get value I was getting correct value.

    But I want to know why the -202 error in parsing.

  • Hi Raghunandana DS,

    I know that currently the documentation for the library is missing and it seems that the error code does gives enough info.
    I believe that the fastest way for you to resolve such issues is through debugging the library itself.
    The code is available under <SDK-ROOT>\source\ti\utils\json\source\.
    You can add the C files to you application sources and debug the error.

    Br,
    Kobi
  • Dear Kobi,
    I did the same, my app is not entering in to Json_parse(), I tried with break points as well UART prints. Nothing is happening in Json_parse(). Before and after the call of Json_parse() prints are working.
    Then shockingly I printed the return value of Json_parse(), and getting "0". I don't know what is the magic happening here.
    Thanks for the suggestion.