• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - Sequencer
  • JSONDecoder

JSONDecoder

JSONDecoder

The JSONDecoder is a sequencer block, that allows decoding input event data from JavaScript Object Notation (JSON) format to output events with decoded data.

Events

NameAppearanceDescription
DecodePredefined input eventInvokes JSON message decoding from EncodedMessage argument. User-added events and Decoded event will be emitted for each decoded argument.
Events with JSON array attribute nameAny number of user-configurable output events for emitting array elementsJSON array attribute to decode from input and send its elements one by one via this event (before Decoded event will be emitted).
Events, that list Data arguments having names specified in DynamicKey or DynamicValue propertiesAny number of user-configurable output events for emitting dynamic key-value pairsThe event will be emitted each time a JSON object contains a simple key-value where the object's key does not have a the corresponding argument in the configuration of the block, DynamicKey or DynamicValue have both been set and there is an Event that lists at least one of the arguments set in DynamicKey or DynamicValue. (All these events will be emitted before Decoded event will be emitted).
DecodedPredefined output eventWill be emitted on Decode event for each argument listed in its Data property and contains values of decoded JSON message attributes as arguments, that are attached to the event via Data property. Data is pre-configured to send the decoded JSON sub-element out in the EncodedMessage argument as this is best suited when you need to forward the event to subsequent JSONEncoder block for JSON sub-element parse. But Data can be altered to send the decoded data out in the other (used added) arguments.

Arguments

NameAppearanceDescription
EncodedMessagePredefined input argumentThe JSON encoded message. Is by default included with Decode event.
JSON attribute nameAny number of user-configurable output argumentsJSON attribute to decode from input and send the argument together with output events

Example

The following block diagram shows how to cascade two JSONDecode blocks to decode a JSON string like this:

{
  "device_id": 1,
  "measurements": [
    {
      "temp": 25.6,
      "humidity": 55
    },
    {
      "temp": 24.5,
      "humidity": 56
    }
  ]
}

By adding an output event named measurements to the first JSONDecoder, a JSON array attribute named measurements will be searched from the input JSON and all its elements will be emitted with the measurements event to the cascaded JSONDecoder1. JSONDecoder1 has arguments temp and humidity added, to instruct the block to search for these attributes in input JSON and when found, assign their values as argument values emitted together with Decoded event.

To better understand the data flow, some Sequencer.DebugPrinter blocks were also connected to the blocks to print into the application output window the time and the data received with events. For the example JSON, their output will look something like this:

20:14:47.086 DEBUG: App.InputDebug: EventIn: Data arguments: EncodedMessage=  {
    "device_id": 1,
    "measurements": [
      {
        "temp": 25.6,
        "humidity": 55
      },
      {
        "temp": 24.5,
        "humidity": 56
      }
    ]
  }
20:14:47.086 DEBUG: App.ArrayElementDebug: EventIn: Data arguments: EncodedMessage={"temp":2.56E1,"humidity":55}
20:14:47.086 DEBUG: App.ArrayElementDebug: EventIn: Data arguments: EncodedMessage={"temp":2.45E1,"humidity":56}
20:14:47.086 DEBUG: App.ToplevelDebug: EventIn: Data arguments: device_id=1
20:14:47.086 DEBUG: App.ArrayElementObjectDebug: EventIn: Data arguments: temp=25.600000381469726562;humidity=55
20:14:47.086 DEBUG: App.ArrayElementObjectDebug: EventIn: Data arguments: temp=24.5;humidity=56

See also JSONEncoder, JSONDecode, and Argument.

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2025 CDP Technologies. Privacy and cookie policy.

Return to top