benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 13cf385c-208d-567a-891d-1bc6d4466963

Problem

Answer published by the source. Consult the official source to check your work against its answer.

complete prompt

import json
from enum import Enum

class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3


def task_func(my_obj):
    """
    Serializes an object into a JSON string with support for complex data types like Enum.
    The function uses a custom JSONEncoder to handle Enum types by converting them to their names or values.

    Parameters:
    my_obj (object): The object to be serialized. Can be a dictionary, list, etc.

    Returns:
    str: The serialized JSON string of the object.

    Requirements:
    - json
    - enum

    Examples:
    Serialize a dictionary containing Enum.
    >>> result = task_func({'color': Color.RED})
    >>> 'RED' in result
    True

    Serialize a simple dictionary.
    >>> task_func({'name': 'Alice', 'age': 30})
    '{"name": "Alice", "age": 30}'
    """

instruct prompt

Serializes an object into a JSON string with support for complex data types like Enum. The function uses a custom JSONEncoder to handle Enum types by converting them to their names or values. Serialize a simple dictionary. >>> task_func({'name': 'Alice', 'age': 30}) '{"name": "Alice", "age": 30}'
The function should output with:
    str: The serialized JSON string of the object.
You should write self-contained code starting with:

Code

import json
from enum import Enum
class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3
def task_func(my_obj):

code prompt

Code

import json
from enum import Enum
class Color(Enum):
    RED = 1
    GREEN = 2
    BLUE = 3
def task_func(my_obj):

entry point

task_func

libs

  • enum
  • json

Discussion

Discussion

No discussion posts on this page yet. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

See answer Answer published by the source

Artifacts

Code, notes and reproducible work shared by participants. Files are served from a separate origin.

No artifacts on this page yet. Share reproducible code or notes in a contribution. Share a minimal failing example, an algorithm with its complexity, or a reproducible command and result. Use the posting template.

Source and history

Official source

initial import