Skip to main content

Parse incoming modeled JSON

Read a known modeled section and validate or reconstruct it with the native API. These examples do not parse arbitrary Slack event or interaction envelopes; language-specific limitations are stated below.

Output

Local preview of the selected language’s tested example. Slack client appearance may differ; controls here do not send requests.

Checked input
Serialized output
{
"type": "section",
"block_id": "incoming",
"text": {
"type": "mrkdwn",
"text": "Checked input"
}
}

Code​

If your app handles Slack interactivity payloads or events, you can parse the JSON back into slackblocks objects with Block.from_dict:

import json
from slackblocks import Block, SectionBlock

slack_request_body = '{"blocks":[{"type":"section","block_id":"incoming","text":{"type":"mrkdwn","text":"Checked input"}}]}'
incoming = json.loads(slack_request_body)

for raw_block in incoming.get("blocks", []):
block = Block.from_dict(raw_block)
if isinstance(block, SectionBlock):
print(block)

Block.from_dict dispatches by type; direct typed parsers also require the matching discriminator. This is a partial parser, not a general Slack JSON loader:

Parse supportBlock types
SupportedAlert, Divider, File, Header, Image, Markdown, Video
Supported subsetSection without accessory; Context with text elements only
Raises NotImplementedErrorActions, Input, RichText, Table, Card, Carousel, Container, Layout (3.2.0+), ContextActions, DataTable, DataVisualization, TaskCard, Plan; Section with accessory; Context with images

Unknown future fields are ignored, so this is not a lossless storage format. Keep the original JSON when forwarding or archiving unsupported or future fields. Text, ConfirmationDialogue, Option, OptionGroup, DispatchActionConfiguration, ConversationFilter, InputParameter, SlackFile, Trigger, and Workflow have composition-object parsers; check individual references rather than assuming every composition type is parseable.

For workflow button styles, use "primary", "danger", a ButtonStyle member (imported from slackblocks.elements), or None (default). Uppercase enum-name strings remain accepted for compatibility.