Home Community Blog Buy Now

Misty Community Forum

Unable to access JSON property from Serial Mistybackpack



function subscribe_to_backpack_data()


    misty.AddReturnProperty("backpack_message", "SerialMessage");

    misty.RegisterEvent("backpack_message", "SerialMessage", 10, true);


function _backpack_message(data)



    data = JSON.parse(JSON.stringify(data.AdditionalResults[0].Message));

    misty.Debug("JSON Response: "+data.res);



    if (data.intent != undefined && data.response != undefined) {

        misty.Debug("Inside here");





def rpi_to_misty(intent, response):
    serial_port.write(("{\"intent\":" + str(intent) + ", \"res\":" + str(response) + "}\r\n").encode())

Hi guys , i facing problem of accessing property from the misty backpack , the screenshot shown above is the property i want to access using “data.res” , how i do a format properly for the response to return as json object . Thanks

Edit : And what is the best way to clear the serial buffer after my data i send out in python?

My code is from CP github MistySkills/ExampleSkills/External Integrations/jetson_serial_interface at master · CPsridharCP/MistySkills · GitHub

Based on the skill messages you have printed, it looks like the data being received is not valid JSON. Specifically the issue is missing double quotes around the values of “intent” and “res” so what’s likely happening is that the JSON.parse is failing to parse the string making the value of data.res as undefined.

Thanks i manage to fix it in python by adding double quote

intent = '"{}"'.format(intent)