<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[MQTT message to JSON issues]]></title><description><![CDATA[<p dir="auto">I'm attempting to send JSON data over MQTT and have the M5 load the different key values into labels. I haven't been successful trying it a few different ways. I think part of the problem is that a b' gets added to the beginning of both the topic an message values received by the MQTT software.</p>
<p dir="auto">For reference, here is the updateProject function called:<br />
<img src="/assets/uploads/files/1727467391301-updatge_project.png" alt="updatge_project.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">And here is the JSON string i'm sending over MQTT:</p>
<pre><code>{ "id": 00004578, "shape": "hex", "total": 856, "cut1": 230, "cut2": 184, "cut3": 207, "cut4": 156, "cut5": 143, "clr1": 230, "clr2": 184, "clr3": 207, "clr4": 156, "clr5": 143 }
</code></pre>
<p dir="auto">First try was this way:<br />
<img src="/assets/uploads/files/1727467138336-simple_load.png" alt="simple_load.png" class=" img-fluid img-markdown" /><br />
This give me an error at the  line of code in the updateProject function assigning the first label value to the appropriate key/value:</p>
<pre><code>TypeError: object with buffer protocol required
</code></pre>
<p dir="auto">The second way was to remove the leading b' that gets inserted (if anyone has a better way to do this, please lmk)<br />
<img src="/assets/uploads/files/1727467555944-remov_b_load.png" alt="remov_b_load.png" class=" img-fluid img-markdown" /><br />
This gives me an error  at the line where it sets projDetails in the MQTT event:</p>
<pre><code>ValueError: syntax error in JSON
</code></pre>
<p dir="auto">The third and fourth way was trying the Dump JSON block alone and trying to remove the b'<br />
<img src="/assets/uploads/files/1727467947340-dump_simple.png" alt="dump_simple.png" class=" img-fluid img-markdown" /><br />
<img src="/assets/uploads/files/1727468637371-dump_complex.png" alt="dump_complex.png" class=" img-fluid img-markdown" /><br />
Both cases gives the error in the first line of the updateProject function where setting the first label</p>
<pre><code>TypeError: string indices must be integers, not str
</code></pre>
<p dir="auto">Then I tried just making the variable the data minus any JSON blocks and put it off to the function to do all the work<br />
<img src="/assets/uploads/files/1727469500453-no_json.png" alt="no_json.png" class=" img-fluid img-markdown" /><br />
This give me an error at the  line of code in the updateProject function assigning the first label value to the appropriate key/value:</p>
<pre><code>ValueError: syntax error in JSON
</code></pre>
<p dir="auto">Not sure how to proceed on this. Any help would be greatly appreciated.</p>
]]></description><link>https://community.m5stack.com/topic/6839/mqtt-message-to-json-issues</link><generator>RSS for Node</generator><lastBuildDate>Wed, 06 May 2026 11:04:29 GMT</lastBuildDate><atom:link href="https://community.m5stack.com/topic/6839.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 27 Sep 2024 20:44:28 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to MQTT message to JSON issues on Fri, 27 Sep 2024 23:18:33 GMT]]></title><description><![CDATA[<p dir="auto">I solved it. See below:</p>
<p dir="auto"><img src="/assets/uploads/files/1727478984737-solution.png" alt="solution.png" class=" img-fluid img-markdown" /></p>
<p dir="auto">First step was removing the b' at the beginning and ' at the end<br />
Then convert that to JSON with "loads json" block<br />
The "loads json" for the individual elements are redundant and you just pull straight from the  json variable</p>
]]></description><link>https://community.m5stack.com/post/26528</link><guid isPermaLink="true">https://community.m5stack.com/post/26528</guid><dc:creator><![CDATA[travisstdenis]]></dc:creator><pubDate>Fri, 27 Sep 2024 23:18:33 GMT</pubDate></item><item><title><![CDATA[Reply to MQTT message to JSON issues on Fri, 27 Sep 2024 22:40:48 GMT]]></title><description><![CDATA[<p dir="auto">Hello <a class="plugin-mentions-user plugin-mentions-a" href="/user/travisstdenis" aria-label="Profile: travisstdenis">@<bdi>travisstdenis</bdi></a></p>
<p dir="auto">have you tried to use <code>decode</code> to convert bytes into a string (instead of <code>replace</code>)? You'll find <code>decode</code> in the <code>Text</code> group.</p>
<p dir="auto">Thanks<br />
Felix</p>
]]></description><link>https://community.m5stack.com/post/26527</link><guid isPermaLink="true">https://community.m5stack.com/post/26527</guid><dc:creator><![CDATA[felmue]]></dc:creator><pubDate>Fri, 27 Sep 2024 22:40:48 GMT</pubDate></item></channel></rss>