benchmarks.wiki / Public workspace

BigCodeBench / BigCodeBench v0.1.0_hf 94f99440-bfb5-52d9-a6d3-c75b4e8adea3

Problem

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

complete prompt

import os
import re
import json
import glob


def task_func(directory_path: str) -> list:
    """
    Protect all double quotes in all JSON files in the specified directory by prepending them with a double backslash.
    
    Functionality:
    - Reads each JSON file in the given directory.
    - Escapes the double quotes by prepending them with a double backslash.
    - Writes back the modified content to the respective JSON file.
    
    Parameters:
    - directory_path (str): Path to the directory containing JSON files.
    
    Returns:
    - list: A list of the processed JSON files.
    
    Requirements:
    - re
    - json
    - glob
    - os

    Raises:
    - FileNotFoundError: If the specified directory does not exist.
    
    Example:
    >>> import tempfile
    >>> import json
    >>> directory = tempfile.mkdtemp()
    >>> with open(directory + "/file1.json", "w") as file:
    ...     json.dump({"name": "John", "age": 30, "city": "New York"}, file)
    >>> with open(directory + "/file2.json", "w") as file:
    ...     json.dump('{"book": "Harry Potter", "author": "J.K. Rowling", "quote": "\\"Magic\\" is everywhere!"}', file)
    >>> files = task_func(directory)
    >>> len(files)
    2
    """

instruct prompt

Protect all double quotes in all JSON files in the specified directory by prepending them with a double backslash. Functionality: - Reads each JSON file in the given directory. - Escapes the double quotes by prepending them with a double backslash. - Writes back the modified content to the respective JSON file.
The function should raise the exception for: FileNotFoundError: If the specified directory does not exist.
The function should output with:
    list: A list of the processed JSON files.
You should write self-contained code starting with:

Code

import os
import re
import json
import glob
def task_func(directory_path: str) -> list:

code prompt

Code

import os
import re
import json
import glob
def task_func(directory_path: str) -> list:

entry point

task_func

libs

  • glob
  • json
  • re
  • os

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