Component: JSON Decoder (Comms: IoT/Cloud): Difference between revisions
Appearance
Created page with "{| style="width:50%" |- | width="20%" style="color:gray;" | Author | Matrix TSL |- | width="20%" style="color:gray;" | Version | 1.0 |- | width="20%" style="color:gray..." |
m Text replacement - "width="90%" style="background-color:#D8C9D8; color:#4B008D;"" to "width="90%" class="mtx-class-macrohead"" |
||
| (8 intermediate revisions by 3 users not shown) | |||
| Line 5: | Line 5: | ||
|- | |- | ||
| width="20%" style="color:gray;" | Version | | width="20%" style="color:gray;" | Version | ||
| 1. | | 1.1 | ||
|- | |- | ||
| width="20%" style="color:gray;" | Category | | width="20%" style="color:gray;" | Category | ||
| Line 15: | Line 15: | ||
Allows dynamic key and value pairs to be collected from a formatted JSON string. | Allows dynamic key and value pairs to be collected from a formatted JSON string. | ||
== | ==Version information== | ||
Library Version, Component Version, Date, Author, Info | |||
4, 1.1, 10-10-24, BR, Allowed for better support of nested array data | |||
4, 1.1, 10-10-24, BR, Removed spaces and new lines etc from the stored data | |||
5, 1.1, 02-15-24, BR, Allowed for better support of nested array data for the FindName function | |||
==Detailed description== | ==Detailed description== | ||
''No detailed description exists yet for this component'' | ''No detailed description exists yet for this component'' | ||
| Line 49: | Line 28: | ||
==Examples== | ==Examples== | ||
===Simple Decode=== | |||
Example program showing how to use a JSON decoder component to parse a simple JSON encoded data string. | |||
{{Fcfile|JSON_Decoder.fcfx|JSON Decoder Example}} | |||
===Simple Encode and Decode=== | |||
Example program showing how to take data and encode it into a JSON string to be sent out over comms. | |||
The example also hows how to decode a received JSON string and pull out values. | |||
{{Fcfile|JSON_Demo.fcfx|JSON_Demo}} | |||
| Line 94: | Line 46: | ||
===FindName=== | ===FindName=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''FindName''' | ||
|- | |- | ||
| colspan="2" | Searches for a name in the JSON data. Returns the data index position. Returns -1 if the name was not found. | | colspan="2" | Searches for a name in the JSON data. Returns the data index position. Returns -1 if the name was not found. | ||
| Line 118: | Line 70: | ||
===ParseJSON=== | ===ParseJSON=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ParseJSON''' | ||
|- | |- | ||
| colspan="2" | Accepts a JSON formatted data string and stores locally in the data buffer ready for parsing. Returns the estimated number of name and data keys present. | | colspan="2" | Accepts a JSON formatted data string and stores locally in the data buffer ready for parsing. Returns the estimated number of name and data keys present. | ||
| Line 137: | Line 89: | ||
===ReadDataAsFloat=== | ===ReadDataAsFloat=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ReadDataAsFloat''' | ||
|- | |- | ||
| colspan="2" | Reads the data of a specific element as a floating point value | | colspan="2" | Reads the data of a specific element as a floating point value | ||
| Line 156: | Line 108: | ||
===ReadDataAsNumber=== | ===ReadDataAsNumber=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ReadDataAsNumber''' | ||
|- | |- | ||
| colspan="2" | Reads the data of a specific element as a numeric integer value | | colspan="2" | Reads the data of a specific element as a numeric integer value | ||
| Line 175: | Line 127: | ||
===ReadDataAsString=== | ===ReadDataAsString=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ReadDataAsString''' | ||
|- | |- | ||
| colspan="2" | Reads the data of a specific element as a string value | | colspan="2" | Reads the data of a specific element as a string value | ||
| Line 194: | Line 146: | ||
===ReadName=== | ===ReadName=== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-comp-macro.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''ReadName''' | ||
|- | |- | ||
| colspan="2" | Reads the name of a specific element | | colspan="2" | Reads the name of a specific element | ||
| Line 214: | Line 166: | ||
==Property reference== | ==Property reference== | ||
{| class="wikitable | {| class="mtx-class-macrotable wikitable" | ||
|- | |- | ||
| width="10%" align="center" | | width="10%" align="center" class="mtx-class-macrohead" | [[File:Fc9-prop-icon.png]] | ||
| width="90%" | | width="90%" class="mtx-class-macrohead" | '''Properties''' | ||
|- | |- | ||
|- | |- | ||
| Line 225: | Line 177: | ||
| colspan="2" | Number of bytes used to store the entire data for the JSON message. Includes names and data values so make sure this is large enough to store everything you want to be able to put into a single JSON data string. | | colspan="2" | Number of bytes used to store the entire data for the JSON message. Includes names and data values so make sure this is large enough to store everything you want to be able to put into a single JSON data string. | ||
|} | |} | ||
==Component Source Code== | |||
Please click here to download the component source project: [https://www.flowcode.co.uk/wiki/componentsource/FC_Comp_Source_JSONDecoder.fcfx FC_Comp_Source_JSONDecoder.fcfx] | |||
Please click here to view the component source code (Beta): [https://www.flowcode.co.uk/FlowchartView/?wfile=componentsource/FC_Comp_Source_JSONDecoder.fcfx FC_Comp_Source_JSONDecoder.fcfx] | |||
Latest revision as of 14:22, 13 July 2026
| Author | Matrix TSL |
| Version | 1.1 |
| Category | Comms: IoT/Cloud |
JSON Decoder component
Allows dynamic key and value pairs to be collected from a formatted JSON string.
Version information
Library Version, Component Version, Date, Author, Info 4, 1.1, 10-10-24, BR, Allowed for better support of nested array data 4, 1.1, 10-10-24, BR, Removed spaces and new lines etc from the stored data 5, 1.1, 02-15-24, BR, Allowed for better support of nested array data for the FindName function
Detailed description
No detailed description exists yet for this component
Examples
Simple Decode
Example program showing how to use a JSON decoder component to parse a simple JSON encoded data string.
JSON Decoder Example
Simple Encode and Decode
Example program showing how to take data and encode it into a JSON string to be sent out over comms.
The example also hows how to decode a received JSON string and pull out values.
Macro reference
FindName
ParseJSON
ReadDataAsFloat
| ReadDataAsFloat | |
| Reads the data of a specific element as a floating point value | |
| Element | |
| Index of the element to read | |
| Return | |
ReadDataAsNumber
| ReadDataAsNumber | |
| Reads the data of a specific element as a numeric integer value | |
| Element | |
| Index of the element to read | |
| Return | |
ReadDataAsString
| ReadDataAsString | |
| Reads the data of a specific element as a string value | |
| Element | |
| Index of the element to read | |
| Return | |
ReadName
| ReadName | |
| Reads the name of a specific element | |
| Element | |
| The Index of the element to read | |
| Return | |
Property reference
Component Source Code
Please click here to download the component source project: FC_Comp_Source_JSONDecoder.fcfx
Please click here to view the component source code (Beta): FC_Comp_Source_JSONDecoder.fcfx