Skip to content

Encoded JSON data is not set correctly inside data field #185

Closed
@sasha-tkachev

Description

@sasha-tkachev

Expected Behavior

JSON format spec section [#3.1.1] states

If the datacontenttype declares the data to contain JSON-formatted content, a JSON serializer MUST translate the data value to a JSON value, and use the member name data to store it inside the JSON representation. The data value MUST be stored directly as a JSON value, rather than as an encoded JSON document represented as a string.

from cloudevents.http import CloudEvent, to_json
import json
json.loads(
     to_json(
         CloudEvent(
             attributes={"type": "my-type", "source": "my-source"},
             data='{"a": "b"}',
         )
     )
 )["data"] =={"a": "b"}

Actual Behavior

When an encoded json value is passed into the cloud even, when to_json is invoked the resulting json object has an encoded json object in the data field and not a JSON representation as required.

from cloudevents.http import CloudEvent, to_json
import json
json.loads(
     to_json(
         CloudEvent(
             attributes={"type": "my-type", "source": "my-source"},
             data='{"a": "b"}',
         )
     )
 )["data"] == '{"a": "b"}' 

Specifications

  • Platform: windows
  • Python Version: python 3.8

#3.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    /spec-v2Smth that is related to the next major version of the CloudEvents specwontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions