• 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
  • JSONEncoder

JSONEncoder

JSONEncoder

The JSONEncoder is a sequencer block, that allows to encode input events data to JavaScript Object Notation (JSON) format as output event with encoded data.

Events

NameAppearanceDescription
Events with JSON array attribute nameAny number of user-configurable input events for array element dataData of this input event will be appended to the JSON message array attribute named as the event
Events, that list Data arguments having names specified in DynamicKey or DynamicValue propertiesAny number of user-configurable input events for appending dynamic key-value pairs to the JSON message.Data arguments that are also listed in DynamicKey and DynamicValue will be used to encode one key-value pair into the JSON message for each time the event is recieved before Encode message is recieved. Any other non dynamic arguments listed in the events Data property will add (or update) an attribute key-value pair defined by the argument's name and value in the JSON message.
EncodePredefined input eventCauses gathered data to be encoded. Event Data arguments will be added and encoded as JSON message attributes
EncodedPredefined output eventWill be emitted on Encode event and contains encoded JSON message in EncodedMessage argument.
InitPredefined input eventWill clear all gathered data and reset the encoder, then will emit Inited
InitedPredefined output eventWill be emitted after Init is done

Arguments

NameAppearanceDescription
JSON attribute nameAny number of user-configurable input argumentsArgument name and value will be encoded to output as JSON attribute name and value
EncodedMessagePredefined output argumentThe encoded JSON message. Will be sent out with Encoded events.

Example

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

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

For that, input arguments temp and humidity were added to the first JSONEncoder, to encode measurement array element JSON objects. These JSON objects are sent to the cascaded JSONEncoder1, into the added input event measurements, that will receive and gather these JSON objects into memory. When Encode event is received the gathered data is encoded with the measurements JSON array included.

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 example JSON, their output will look something like this:

20:57:09.285 DEBUG: App.ArrayElementDebug: EventIn: Data arguments: temp=25.600000000000001421;humidity=55
20:57:09.285 DEBUG: App.ArrayElementObjectDebug: EventIn: All arguments: EncodedMessage='{\"temp\":2.56E1,\"humidity\":5.5E1}'
20:57:26.284 DEBUG: App.ArrayElementDebug: EventIn: Data arguments: temp=24.5;humidity=56
20:57:26.285 DEBUG: App.ArrayElementObjectDebug: EventIn: All arguments: EncodedMessage='{\"temp\":2.45E1,\"humidity\":5.6E1}'
20:57:28.583 DEBUG: App.EncodeDebug: EventIn: Data arguments: device_id=1
20:57:28.583 DEBUG: App.EncoedJSONDebug: EventIn: Data arguments: EncodedMessage={"measurements":[{"temp":2.56E1,"humidity":5.5E1},{"temp":2.45E1,"humidity":5.6E1}],"device_id":1}

See also JSONDecoder, JSONEncode, 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