instruction_seed
stringlengths
217
5.42k
response_seed
stringlengths
16
128k
response
stringlengths
10
14.5k
__original_row_idx
int64
0
35.9k
conversations
listlengths
2
2
You are tasked with creating a Python function `update_style_info` that takes a JSON object representing a style's metadata and updates its information based on the provided parameters. The function should adhere to the following requirements: 1. The JSON object will have the same structure as the given code snippet...
```python import json from datetime import datetime def update_style_info(json_data, new_css, new_format, new_author_name): """ Updates the style's metadata with new CSS, format, and author's name. Parameters: - json_data (dict): The JSON object containing the style's metadata. - new_css (st...
To create the `update_style_info` function as specified, we will follow the requirements outlined in the prompt. Let's break down the process: 1. We'll take a JSON object and a few parameters that represent new values for CSS, format, and author's name. 2. The function will check for the new values and update the corr...
10,000
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `update_style_info` that takes a JSON object representing a style's metadata and updates its information based on the provided parameters. The function should adhere to the following requirements:\n\n1. The JSON object will have...
Design a function `generate_nft_metadata` that takes a dictionary representing the base attributes of an NFT (Non-Fungible Token) and returns a JSON string representing the complete metadata for that NFT. The function should add a unique identifier and a timestamp to the metadata. The base attributes will include the...
```python import json import uuid from datetime import datetime def generate_nft_metadata(base_attributes): """ Generates a JSON string representing the complete metadata for an NFT. Parameters: - base_attributes (dict): A dictionary with the base attributes of the NFT. Returns: - s...
Sure! Here's how you can implement the `generate_nft_metadata` function in Python. This function will take a dictionary representing the base attributes of an NFT, validate the input, and generate the complete metadata including a unique identifier and a timestamp. ```python import json import uuid from datetime impor...
10,001
[ { "from": "human", "value": "\n\nDesign a function `generate_nft_metadata` that takes a dictionary representing the base attributes of an NFT (Non-Fungible Token) and returns a JSON string representing the complete metadata for that NFT. The function should add a unique identifier and a timestamp to the met...
Create a Python function `update_exercise_metadata` that takes a JSON string representing the metadata of a programming exercise and updates it according to the following rules: 1. If the `blurb` field contains the string "TODO", replace it with a provided non-empty string. If the provided string is empty, raise a V...
```python import json def update_exercise_metadata(json_str, new_blurb, username): """ Updates the metadata of a programming exercise. :param json_str: A JSON string representing the exercise metadata. :param new_blurb: A non-empty string to replace the TODO in the blurb field. :param username: ...
To create the `update_exercise_metadata` function as you described, we can follow these steps: 1. Parse the input JSON string into a Python dictionary. 2. Check and update the `blurb` field. 3. Add the `updated_by` field with the provided username. 4. Modify the filenames in the `files` field based on the specified co...
10,002
[ { "from": "human", "value": "\n\nCreate a Python function `update_exercise_metadata` that takes a JSON string representing the metadata of a programming exercise and updates it according to the following rules:\n\n1. If the `blurb` field contains the string \"TODO\", replace it with a provided non-empty str...
Write a Python program that reads a JSON configuration file for a Java development environment and updates all configurations to use a new version of the JavaFX SDK. The path to the new JavaFX SDK should be provided as an argument to the program. The program should also ensure that the `vmArgs` field contains the cor...
```python import json def update_javafx_sdk(config_file_path, new_sdk_path): """ Updates the JavaFX SDK path in the vmArgs of each configuration in the given JSON file. :param config_file_path: Path to the JSON configuration file. :param new_sdk_path: The new path to the JavaFX SDK to be used. "...
To accomplish the task of updating the JavaFX SDK path in a JSON configuration file, we can write a Python program that reads the configurations, updates them, and saves the changes. Below is an implementation of the `update_javafx_sdk` function that performs the required actions. First, ensure that you have Python i...
10,003
[ { "from": "human", "value": "\n\nWrite a Python program that reads a JSON configuration file for a Java development environment and updates all configurations to use a new version of the JavaFX SDK. The path to the new JavaFX SDK should be provided as an argument to the program. The program should also ensu...
You are tasked with writing a Python function `aggregate_election_results` that processes a list of dictionaries containing election data for various polling stations within a region. Each dictionary represents a polling station and contains information about the region, polling station, and election results for two ...
```python from typing import List, Dict, Any def aggregate_election_results(election_data: List[Dict[str, Any]]) -> Dict[str, int]: """ Aggregates the total votes for general election and presidential election from a list of polling station data. :param election_data: A list of dictionaries, where each ...
To implement the function `aggregate_election_results`, we need to process a list of dictionaries, extracting and aggregating the total vote counts for both the general election and the presidential election. We will consider any `null` values for the `toplam_oy` fields as 0, ensuring that our aggregation is accurate. ...
10,004
[ { "from": "human", "value": "\n\nYou are tasked with writing a Python function `aggregate_election_results` that processes a list of dictionaries containing election data for various polling stations within a region. Each dictionary represents a polling station and contains information about the region, pol...
Write a Python function `normalize_journal_data` that takes a JSON object representing a journal entry and normalizes it by filling in missing fields with default values. The function should adhere to the following specifications: - The JSON object will have the structure as shown in the given code snippet. - The fi...
```python import json def normalize_journal_data(journal_entry): """ Normalizes a journal entry JSON object by filling missing fields with default values. Parameters: journal_entry (dict): A dictionary representing a journal entry. Returns: dict: The normalized journal entry with mi...
Here's a Python function `normalize_journal_data` that meets the specified requirements. It takes a JSON object (represented as a dictionary in Python) and normalizes it by filling in missing fields with specified default values. ```python def normalize_journal_data(journal_entry): """ Normalize a journal entr...
10,005
[ { "from": "human", "value": "\n\nWrite a Python function `normalize_journal_data` that takes a JSON object representing a journal entry and normalizes it by filling in missing fields with default values. The function should adhere to the following specifications:\n\n- The JSON object will have the structure...
Write a Python function `calculate_influence_score` that takes a JSON string representing a Twitter user's profile and calculates their influence score based on the following formula: ``` Influence Score = (Average Retweet Count * 0.4) + (Average Favorite Count * 0.3) + (Followers Count * 0.2) + (Verified Bonus) ```...
```python import json def calculate_influence_score(json_profile): """ Calculate the influence score of a Twitter user based on their profile data. :param json_profile: A JSON string containing the Twitter user's profile data. :return: The calculated influence score as a float rounded to two dec...
To implement the `calculate_influence_score` function as described in your request, we can follow these steps: 1. Parse the JSON string into a Python dictionary. 2. Extract the required values: average retweet count, average favorite count, followers count, and whether the user is verified. 3. Calculate the influence ...
10,006
[ { "from": "human", "value": "\n\nWrite a Python function `calculate_influence_score` that takes a JSON string representing a Twitter user's profile and calculates their influence score based on the following formula:\n\n```\nInfluence Score = (Average Retweet Count * 0.4) + (Average Favorite Count * 0.3) + ...
You are tasked with creating a Python function `parse_package_info` that takes a JSON string representing a package information similar to the one provided in the code snippet and returns a dictionary with specific details about the package. The function should extract the following information: - Package name - Pac...
```python import json def parse_package_info(json_string: str) -> dict: """ Parses a JSON string containing package information and extracts specific details. Parameters: - json_string (str): A JSON string representing package information. Returns: - dict: A dictionary with keys 'name', 'de...
To implement the `parse_package_info` function, we will use the built-in `json` module in Python to parse the JSON string and extract the required information. Here's a complete implementation of the function: ```python import json def parse_package_info(json_string: str) -> dict: """ Parses a JSON string con...
10,007
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `parse_package_info` that takes a JSON string representing a package information similar to the one provided in the code snippet and returns a dictionary with specific details about the package.\n\nThe function should extract th...
Write a Python function `update_package_version(package_json, package_name, new_version)` that takes a JSON string representing a `package.json` file (commonly used in JavaScript projects), the name of a dependency package, and a new version number. The function should update the version of the specified package in t...
```python import json def update_package_version(package_json, package_name, new_version): """ Updates the version of a specified package in the dependencies of a package.json file. :param package_json: A JSON string representing a package.json file. :param package_name: The name of the package ...
Here's a Python function that accomplishes what you've described. This function takes a JSON string representing a `package.json` file, updates the version of a specified dependency, and returns the updated JSON string. It also handles errors related to invalid JSON structure. ```python import json def update_package...
10,008
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_version(package_json, package_name, new_version)` that takes a JSON string representing a `package.json` file (commonly used in JavaScript projects), the name of a dependency package, and a new version number. The function should updat...
Write a Python function `update_package_version` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and two arguments: `package_name` (a string) and `new_version` (a string). The function should update the version of the specified package in the `dependencies` section of t...
```python import json def update_package_version(json_str, package_name, new_version): """ Updates the version of a specified package in the dependencies of a package.json file. :param json_str: A JSON string representing a package.json file. :param package_name: The name of the package to updat...
Certainly! Below is the Python function `update_package_version` that meets the specified requirements: ```python import json def update_package_version(json_str, package_name, new_version): try: # Parse the input JSON string package_data = json.loads(json_str) # Check if 'depende...
10,009
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_version` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and two arguments: `package_name` (a string) and `new_version` (a string). The function should update the version of the specified...
Design a function `parse_mission_data` that takes a JSON string representing the mission data of a game and extracts relevant information to create a summary of the mission. The function should return a dictionary with the following keys and their corresponding values: - `mission_name`: The name of the mission. - `m...
```python import json def parse_mission_data(json_data): """ Parses the given JSON string containing mission data and extracts relevant information. Parameters: - json_data (str): A JSON string representing the mission data. Returns: - dict: A dictionary with keys 'mission_name', 'm...
To implement the `parse_mission_data` function, we will leverage Python's built-in `json` module to parse the incoming JSON string. The function will then extract required keys from the parsed data and handle potential errors related to missing information or invalid JSON. Here's how we can do this: ```python import j...
10,010
[ { "from": "human", "value": "\n\nDesign a function `parse_mission_data` that takes a JSON string representing the mission data of a game and extracts relevant information to create a summary of the mission. The function should return a dictionary with the following keys and their corresponding values:\n\n- ...
Design a Python function `extract_relationship_data` that takes a JSON object representing a bundle of cybersecurity threat information and extracts specific details about the relationships between entities within the bundle. The function should adhere to the following requirements: - The input JSON object follows t...
```python import json def extract_relationship_data(bundle_json): """ Extracts relationship data from a STIX bundle JSON object. Parameters: bundle_json (dict): A JSON object representing a STIX bundle. Returns: list: A list of dictionaries containing relationship information. """ t...
To implement the `extract_relationship_data` function as described, we will assume that the input JSON object is structured according to the STIX format, particularly focusing on the relationships. Here's how you can create this function in Python: ```python import json def extract_relationship_data(stix_bundle): ...
10,011
[ { "from": "human", "value": "\n\nDesign a Python function `extract_relationship_data` that takes a JSON object representing a bundle of cybersecurity threat information and extracts specific details about the relationships between entities within the bundle. The function should adhere to the following requi...
You are tasked with creating a system that manages employee day-off requests for a company. The system should be able to process a list of employee records, each containing personal information and day-off requests, and perform various operations on this data. Write a Python program that accomplishes the following t...
```python import json def process_dayoff_requests(json_data): """ Processes day-off requests from a JSON string of employee data. Parameters: - json_data (str): A JSON string containing a list of employees and their day-off requests. Returns: - List[Dict[str, Any]]: A list of dictio...
Here's how you can implement the specified functionality in Python. We'll define a function `process_dayoff_requests(json_data)` that will handle loading the JSON data, validating the day-off requests, and generating the report. Below is the complete code: ```python import json def process_dayoff_requests(json_data)...
10,012
[ { "from": "human", "value": "\n\nYou are tasked with creating a system that manages employee day-off requests for a company. The system should be able to process a list of employee records, each containing personal information and day-off requests, and perform various operations on this data.\n\nWrite a Pyt...
You are tasked with creating a Python function `analyze_vulnerability_data` that processes JSON data representing a cybersecurity vulnerability report. The function should extract and return a summary of the vulnerability, including its ID, status, severity, and a brief description in English. The JSON data structur...
```python import json def analyze_vulnerability_data(json_data): """ Analyzes vulnerability data in JSON format and extracts a summary. Parameters: - json_data (str): A JSON string representing the vulnerability report. Returns: - dict: A dictionary with keys 'id', 'status', 'severity', and...
Sure! Below is a Python function `analyze_vulnerability_data` that adheres to the requirements you've provided. It processes a JSON string representing a cybersecurity vulnerability report and extracts the necessary information, returning it as a dictionary. In the case of missing information, it raises a `ValueError` ...
10,013
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `analyze_vulnerability_data` that processes JSON data representing a cybersecurity vulnerability report. The function should extract and return a summary of the vulnerability, including its ID, status, severity, and a brief desc...
You are tasked with creating a Python function `update_navigation_bar` that takes a JSON object representing a configuration for a mobile application and updates the navigation bar properties based on the provided parameters. The function should adhere to the following requirements: 1. The function should accept thr...
```python import json def update_navigation_bar(config_json, background_color, title_text): """ Updates the navigation bar properties in the given JSON configuration object. Parameters: - config_json (dict): The JSON object representing the app configuration. - background_color (str): The new ba...
Here is how you can implement the `update_navigation_bar` function in Python according to the specifications you provided: ```python import json def update_navigation_bar(config_json, background_color=None, title_text=None): """ Updates the navigation bar properties in the given app configuration. Parame...
10,014
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `update_navigation_bar` that takes a JSON object representing a configuration for a mobile application and updates the navigation bar properties based on the provided parameters. The function should adhere to the following requi...
Write a Python function `extract_artwork_details` that takes a JSON string representing an artwork's metadata and extracts specific details into a more concise dictionary. The function should focus on the following details: `accession_number`, `artist`, `classification`, `country`, `dated`, `department`, `dimension`,...
```python import json def extract_artwork_details(json_string: str) -> dict: # Parse the JSON string into a dictionary artwork_data = json.loads(json_string) # Define the keys to extract keys_to_extract = [ 'accession_number', 'artist', 'classification', 'country', 'dated', 'depa...
Certainly! Below is the implementation of the `extract_artwork_details` function as per your requirements: ```python import json def extract_artwork_details(json_string: str) -> dict: """ Extracts specific details from an artwork's metadata JSON string. Parameters: - json_string (str): A JSON string ...
10,015
[ { "from": "human", "value": "\n\nWrite a Python function `extract_artwork_details` that takes a JSON string representing an artwork's metadata and extracts specific details into a more concise dictionary. The function should focus on the following details: `accession_number`, `artist`, `classification`, `co...
Design a function `generate_item_metadata` that takes an item's template ID, name, description, image URL, IPFS hash (optional), slot, and a list of attributes as input and generates a JSON object representing the item's metadata. The function should follow these specifications: - The `template` should be a string r...
```python import json def generate_item_metadata(template, name, description, image, slot, attributes, ipfs=""): """ Generates a JSON object representing an item's metadata. :param template: A string representing the unique ID of the item template. :param name: A string representing the name of the ...
Below is a Python function named `generate_item_metadata` that implements the specifications you provided. It constructs a JSON object representing an item's metadata based on the parameters given. ```python import json def generate_item_metadata(template, name, description, image, slot, attributes, ipfs=""): # C...
10,016
[ { "from": "human", "value": "\n\nDesign a function `generate_item_metadata` that takes an item's template ID, name, description, image URL, IPFS hash (optional), slot, and a list of attributes as input and generates a JSON object representing the item's metadata. The function should follow these specificati...
You are given a JSON object representing a digital collectible (NFT) with various attributes. Your task is to write a Python function `summarize_nft_attributes(json_data)` that takes this JSON object as input and returns a summary of the NFT's attributes. The summary should include the following information: 1. The ...
```python import json def summarize_nft_attributes(json_data): """ Summarizes the attributes of an NFT given its JSON representation. Parameters: - json_data (str): A JSON string representing the NFT. Returns: - summary (dict): A dictionary containing: - 'total_attributes' (...
Here’s a Python function that summarizes the attributes of a digital collectible (NFT) based on the requirements you've provided: ```python import json def summarize_nft_attributes(json_data): """ Summarizes the attributes of a digital collectible (NFT). Parameters: json_data (dict): A JSON object re...
10,017
[ { "from": "human", "value": "\n\nYou are given a JSON object representing a digital collectible (NFT) with various attributes. Your task is to write a Python function `summarize_nft_attributes(json_data)` that takes this JSON object as input and returns a summary of the NFT's attributes. The summary should ...
You are tasked with creating a Python function that updates a JSON configuration for a website project. The function should take a JSON string representing the configuration, a dictionary of script updates, and optionally a new version number. It should update the `scripts` section of the JSON with the new commands p...
```python import json def update_project_config(json_config: str, script_updates: dict, new_version: str = None) -> str: """ Updates the project configuration JSON with new script commands and optionally a new version number. :param json_config: A JSON string representing the project configuration. ...
Here's a Python function that meets the specifications you've described. The function will update the `scripts` section of the JSON configuration with the new commands from the provided dictionary, and it will also update the `version` field if a new version number is specified. ```python import json def update_proje...
10,018
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that updates a JSON configuration for a website project. The function should take a JSON string representing the configuration, a dictionary of script updates, and optionally a new version number. It should update the `scripts` ...
You are tasked with creating a function `generate_character_profile` that takes a JSON string representing a character's attributes and returns a dictionary with the character's profile. The profile should include the character's edition number and a dictionary of attributes where the keys are the trait types and the...
```python import json def generate_character_profile(json_string): """ Parses a JSON string representing a character's attributes and returns a dictionary with the character's profile, including edition number and a dictionary of traits. :param json_string: A JSON string representing the charact...
To create the function `generate_character_profile` that processes a JSON string input and returns the desired character profile format, we'll use the `json` module to parse the input JSON and then structure it according to the specified format. Here's how you can implement this function: ```python import json def ...
10,019
[ { "from": "human", "value": "\n\nYou are tasked with creating a function `generate_character_profile` that takes a JSON string representing a character's attributes and returns a dictionary with the character's profile. The profile should include the character's edition number and a dictionary of attributes...
You are tasked with writing a Python program that will read a JSON object representing a software project's package information and perform the following operations: 1. Verify if a given package is present in the dependencies. 2. Update the version of a given package to a new version. 3. Add a new package with its v...
```python import json class PackageManager: def __init__(self, package_info): """ Initializes the PackageManager with the given package information. :param package_info: A JSON string representing the package information. """ try: self.package_data = j...
Below is the Python program that implements a `PackageManager` class to manage a software project's package information as specified. This class handles basic operations like checking for a package, updating its version, adding new packages, and removing packages from the list of dependencies. ```python import json c...
10,020
[ { "from": "human", "value": "\n\nYou are tasked with writing a Python program that will read a JSON object representing a software project's package information and perform the following operations:\n\n1. Verify if a given package is present in the dependencies.\n2. Update the version of a given package to ...
Write a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and updates it according to the following rules: 1. If the `version` field is present, increment the minor version by 1 (e.g., "1.0.0" becomes "1.1.0"). 2. If the `scripts` fi...
```python import json from packaging import version def update_package_json(json_str): """ Updates the given package.json string according to predefined rules. Parameters: - json_str: A string representation of a package.json file. Returns: - A string representation of the updated p...
To accomplish the task of updating a `package.json` file according to the specified rules, we can use the `json` module in Python to parse the JSON string, update its contents, and then emit it back as a string. Below is the implementation of the function `update_package_json`: ```python import json import re def upd...
10,021
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and updates it according to the following rules:\n\n1. If the `version` field is present, increment the minor version by 1 (e.g., \"1...
Write a Python function `parse_dockerfile_metadata` that takes a JSON string representing the metadata of a Dockerfile formatting tool and returns a dictionary with the following keys and their corresponding values: - `description`: A string containing the short description of the tool. - `license`: A string contain...
```python import json def parse_dockerfile_metadata(json_str): """ Parses the given JSON string containing metadata of a Dockerfile formatting tool and returns a dictionary with specific keys and values. :param json_str: A JSON string representing the metadata. :return: A dictionary with keys: '...
Certainly! Below is a Python function `parse_dockerfile_metadata` that processes a JSON string representing the metadata of a Dockerfile formatting tool. This function extracts the required information and returns it in the specified format. ```python import json def parse_dockerfile_metadata(json_str): # Parse t...
10,022
[ { "from": "human", "value": "\n\nWrite a Python function `parse_dockerfile_metadata` that takes a JSON string representing the metadata of a Dockerfile formatting tool and returns a dictionary with the following keys and their corresponding values:\n\n- `description`: A string containing the short descripti...
Write a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and a dictionary of updates. The function should apply the updates to the JSON object and return the updated JSON string. The updates can include adding new dependencies, updat...
```python import json def update_package_json(package_json_str, updates): """ Updates the package.json string with the provided updates. :param package_json_str: A string representation of the package.json file. :param updates: A dictionary containing updates to be applied. :return: An updated p...
You can create the `update_package_json` function using the `json` module in Python to handle JSON data. The function will take a JSON string and a dictionary of updates, parse the JSON string, apply the updates as specified, and then return the modified JSON string. Here's how you can implement the function: ```pyth...
10,023
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and a dictionary of updates. The function should apply the updates to the JSON object and return the updated JSON string. The updates...
Write a Python program that reads a JSON configuration file for a development environment and updates it according to the following requirements: 1. Add a new configuration for a Python Flask server with the following attributes: - "name": "Flask: Server" - "type": "python" - "request": "launch" - "p...
```python import json def update_configuration(file_path): """ Updates the JSON configuration file at the given file_path according to the specified requirements. """ with open(file_path, 'r') as file: config = json.load(file) # Add new Flask server configuration flask_config = { ...
Here's a Python program that accomplishes the specified requirements for updating a JSON configuration file. The program reads from a `launch.json` file, makes the necessary updates, and writes the updated configuration back to the file. ### Python Program ```python import json import os def update_config(filepath):...
10,024
[ { "from": "human", "value": "\n\nWrite a Python program that reads a JSON configuration file for a development environment and updates it according to the following requirements:\n\n1. Add a new configuration for a Python Flask server with the following attributes:\n - \"name\": \"Flask: Server\"\n - ...
In the game of Minecraft, players can craft various items using different materials. The crafting recipes can be represented in JSON format. Your task is to write a Python function that takes a JSON string representing a Minecraft crafting recipe and returns a human-readable description of the recipe. The JSON strin...
```python import json def describe_crafting_recipe(json_string): """ Takes a JSON string representing a Minecraft crafting recipe and returns a human-readable description of the recipe. """ recipe = json.loads(json_string) type_ = recipe['type'] group = recipe['group'] pattern = recip...
Here's a Python function that reads a JSON string representing a Minecraft crafting recipe and returns a human-readable description of that recipe. The function parses the JSON, extracts the necessary elements, and formats the output accordingly. ```python import json def describe_crafting_recipe(recipe_json_str): ...
10,025
[ { "from": "human", "value": "\n\nIn the game of Minecraft, players can craft various items using different materials. The crafting recipes can be represented in JSON format. Your task is to write a Python function that takes a JSON string representing a Minecraft crafting recipe and returns a human-readable...
Design a Python function `generate_entity_class` that takes a JSON object representing the configuration for an entity in a software project and generates a corresponding Python class code as a string. The JSON object contains the following keys: - `name`: The name of the entity. - `fields`: A list of fields that th...
```python import json def generate_entity_class(entity_config): """ Generates a Python class code as a string based on the given entity configuration. :param entity_config: A JSON object containing the configuration for the entity. :return: A string representing the Python class code for the entity....
To create the Python function `generate_entity_class` that generates a Python class code based on the provided JSON configuration, we can start by parsing the JSON object to extract its fields and their metadata. Then we will construct a string that represents the Python class, incorporating the necessary attributes, t...
10,026
[ { "from": "human", "value": "\n\nDesign a Python function `generate_entity_class` that takes a JSON object representing the configuration for an entity in a software project and generates a corresponding Python class code as a string. The JSON object contains the following keys:\n\n- `name`: The name of the...
Create a Python function `extract_document_info` that takes a JSON object representing legal document data and extracts specific information about the document and its historical impacts. The function should return a dictionary with the following keys and their corresponding values: - `uri`: The URI of the document. ...
```python import json def extract_document_info(json_data): """ Extracts information about a legal document and its historical impacts from a JSON object. :param json_data: A JSON object containing legal document data. :return: A dictionary with extracted information. """ data = json_data...
Here's a Python function `extract_document_info` that meets your requirements. It takes a JSON object and extracts the specified information, handling any missing data appropriately. ```python def extract_document_info(document_data): # Initialize the extracted information dictionary extracted_info = { ...
10,027
[ { "from": "human", "value": "\nCreate a Python function `extract_document_info` that takes a JSON object representing legal document data and extracts specific information about the document and its historical impacts. The function should return a dictionary with the following keys and their corresponding v...
Write a Python function `update_package_version` that takes a JSON string representing a package configuration (similar to the given code snippet) and two arguments: `package_name` and `new_version`. The function should update the version of the specified package within the `dependencies` or `devDependencies` section...
```python import json def update_package_version(json_string, package_name, new_version): """ Updates the version of a specified package in the JSON configuration. :param json_string: A string containing JSON configuration data. :param package_name: The name of the package to update. :param new_...
Certainly! Below is the implementation of the `update_package_version` function that updates the version of a specified package in its JSON configuration, along with test cases to validate its correctness. ```python import json def update_package_version(json_string, package_name, new_version): try: # Par...
10,028
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_version` that takes a JSON string representing a package configuration (similar to the given code snippet) and two arguments: `package_name` and `new_version`. The function should update the version of the specified package within the ...
Write a Python function `extract_package_names` that takes a JSON object representing a dependency graph and returns a list of package names. The JSON object has a specific structure where dependencies are listed under the key `"ngDeps"`, and each dependency can either be a string or an object with a key `"1"` that c...
```python import json def extract_package_names(json_obj): """ Extracts and returns a list of package names from a given JSON object representing a dependency graph. The function ignores optional dependencies. :param json_obj: A JSON object containing the dependency graph. :return: A list of pac...
To accomplish the task of extracting package names from the provided JSON structure, we can write a Python function called `extract_package_names`. This function will specifically look for the `"ngDeps"` key in the JSON object. For each dependency listed under this key, it will determine whether the dependency is a str...
10,029
[ { "from": "human", "value": "\n\nWrite a Python function `extract_package_names` that takes a JSON object representing a dependency graph and returns a list of package names. The JSON object has a specific structure where dependencies are listed under the key `\"ngDeps\"`, and each dependency can either be ...
In the game of Minecraft, players can craft new items by following specific recipes. A recipe can be represented in JSON format, which defines the type of crafting, the pattern of materials needed, and the resulting item. Your task is to write a function `craft_item(recipe_json)` that takes a JSON string representing...
```python import json def craft_item(recipe_json): """ Parses a JSON string representing a Minecraft crafting recipe and returns a dictionary with details of the crafted item. :param recipe_json: JSON string representing the crafting recipe :return: Dictionary with 'crafted_item' and 'quantity' ...
To accomplish the task, we need to create a function named `craft_item` that takes a JSON string as input and parses it to extract the necessary information. We will make use of Python's `json` module for parsing the JSON data. Here’s how the function will work step by step: 1. Parse the JSON string to a Python dictio...
10,030
[ { "from": "human", "value": "\n\nIn the game of Minecraft, players can craft new items by following specific recipes. A recipe can be represented in JSON format, which defines the type of crafting, the pattern of materials needed, and the resulting item. Your task is to write a function `craft_item(recipe_j...
Write a Python program that reads a JSON file containing a package configuration (similar to the given code snippet, which represents a `package.json` file from a Node.js project) and performs the following tasks: 1. Validates that the JSON structure contains the required fields: `name`, `version`, `scripts`, and `d...
```python import json from packaging.version import Version # Importing the required packages def read_json_file(file_path): with open(file_path, 'r') as file: return json.load(file) def write_json_file(file_path, data): with open(file_path, 'w') as file: json.dump(data, file, indent=2) def...
Sure! Below is a Python program that accomplishes the tasks you specified: validating a JSON structure, extracting dependency names, adding a new script, incrementing a patch version, and saving the updated configuration back to a file. ```python import json import re def load_package_json(file_path): """Load the...
10,031
[ { "from": "human", "value": "\n\nWrite a Python program that reads a JSON file containing a package configuration (similar to the given code snippet, which represents a `package.json` file from a Node.js project) and performs the following tasks:\n\n1. Validates that the JSON structure contains the required...
Write a Python function `validate_business_data` that takes a JSON string representing business registration data and validates it against a set of rules. The function should return a dictionary with the validation status and any error messages. The business registration data should adhere to the following rules: 1....
```python import re from datetime import datetime def validate_business_data(json_data): """ Validates business registration data in JSON format against predefined rules. Parameters: json_data (str): A JSON string containing business registration data. Returns: dict: A dictionary wi...
To implement the `validate_business_data` function, we'll break down the requirements and validate the input JSON string accordingly. We'll parse the JSON string into a Python dictionary, and then apply each rule to check for compliance. Finally, we'll collect any error messages and return them in the specified format....
10,032
[ { "from": "human", "value": "\n\nWrite a Python function `validate_business_data` that takes a JSON string representing business registration data and validates it against a set of rules. The function should return a dictionary with the validation status and any error messages.\n\nThe business registration ...
You are tasked with creating a Python function that updates the configuration of a mobile application based on a given JSON object. The function should be able to handle the following updates: 1. Update the application version. 2. Toggle the orientation between "portrait" and "landscape". 3. Update the iOS support f...
```python import json def update_app_config(config_json: str, updates: dict) -> str: config = json.loads(config_json) # Update the application version if "version" in updates: config["expo"]["version"] = updates["version"] # Toggle the orientation if "toggle_orientation" in upda...
To implement the `update_app_config` function based on the requirements provided, you can follow these steps: 1. Parse the input JSON string into a Python dictionary. 2. Apply the updates provided in the `updates` dictionary according to the specific keys. 3. Convert the Python dictionary back to a JSON string and ret...
10,033
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that updates the configuration of a mobile application based on a given JSON object. The function should be able to handle the following updates:\n\n1. Update the application version.\n2. Toggle the orientation between \"portrai...
Design a function `extract_cve_details` that takes a JSON object representing a Common Vulnerabilities and Exposures (CVE) entry and extracts specific details about the CVE. The function should return a dictionary containing the CVE ID, the state of the CVE, the description of the vulnerability, and a list of referen...
```python import json def extract_cve_details(cve_json): """ Extracts details from a CVE JSON object and returns a dictionary with specific fields. Parameters: cve_json (dict): A JSON object representing a CVE entry. Returns: dict: A dictionary containing the CVE ID, state, description, and...
Here is a Python function that adheres to your specifications for extracting details from a CVE JSON object: ```python import json def extract_cve_details(cve_json): # Initialize the output dictionary cve_details = { 'cve_id': None, 'state': None, 'description': None, 'referenc...
10,034
[ { "from": "human", "value": "\n\nDesign a function `extract_cve_details` that takes a JSON object representing a Common Vulnerabilities and Exposures (CVE) entry and extracts specific details about the CVE. The function should return a dictionary containing the CVE ID, the state of the CVE, the description ...
You are tasked with creating a Python function `analyze_petition_data` that processes information about a political petition. The function will take a JSON string representing the petition data and return a dictionary with specific details extracted and calculated from the input. The function should perform the foll...
```python import json from datetime import datetime def analyze_petition_data(json_data): """ Analyzes petition data from a JSON string and extracts specific details. Parameters: - json_data (str): A JSON string representing the petition data. Returns: - dict: A dictionary containing the pe...
To implement the `analyze_petition_data` function as specified, we will need to use Python's `json` module to parse the JSON string and the `datetime` module to handle date calculations. Below is the complete code for the function: ```python import json from datetime import datetime def analyze_petition_data(json_dat...
10,035
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `analyze_petition_data` that processes information about a political petition. The function will take a JSON string representing the petition data and return a dictionary with specific details extracted and calculated from the i...
You are tasked with creating a Python function `validate_business_record` that takes a JSON string representing a business record and validates it against certain criteria. The JSON structure is similar to the given code snippet. The function should perform the following validations: 1. `cedula_rnc` must be a string...
```python import re from datetime import datetime def validate_business_record(json_string): """ Validates a business record JSON string against specific criteria. :param json_string: JSON string representing a business record :return: True if all validations pass, otherwise raises ValueError ...
To create the `validate_business_record` function as per your requirements, we will use the `json` module to parse the input JSON string. We will also utilize regular expressions to validate strings for specific character rules and check the format of the date. Here's the implementation: ```python import json import r...
10,036
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `validate_business_record` that takes a JSON string representing a business record and validates it against certain criteria. The JSON structure is similar to the given code snippet. The function should perform the following val...
You are tasked with creating a function `filter_videos_by_duration` that takes a JSON string representing a page of video items and filters the videos based on a specified duration range. The function should return a JSON string containing only the videos whose duration is within the given range (inclusive). The JSO...
```python import json def filter_videos_by_duration(json_data, min_duration, max_duration): """ Filters the videos from the input JSON data based on the specified duration range. :param json_data: A JSON string representing a page of video items. :param min_duration: An integer for the minimum d...
You can create a function named `filter_videos_by_duration` that processes the given JSON string, filters the video items based on the specified duration range, and returns the filtered results in the required JSON format. Below is an implementation of the function in Python: ```python import json def filter_videos_b...
10,037
[ { "from": "human", "value": "\n\nYou are tasked with creating a function `filter_videos_by_duration` that takes a JSON string representing a page of video items and filters the videos based on a specified duration range. The function should return a JSON string containing only the videos whose duration is w...
Design a Python function `get_pokemon_data` that takes a JSON string representing a Pokémon's data and returns a dictionary with specific details about the Pokémon. The function should extract the following information: - `name`: The name of the Pokémon. - `types`: A list of the Pokémon's types. - `abilities`: A lis...
```python import json def get_pokemon_data(json_data): """ Extracts specific details from a JSON string representing a Pokémon's data. Parameters: - json_data (str): A JSON string containing the Pokémon's data. Returns: - dict: A dictionary with the Pokémon's name, types, non-hidden...
To create the function `get_pokemon_data`, we'll follow these steps: 1. Parse the JSON string into a Python dictionary. 2. Extract the desired information from the dictionary. 3. Return the information in a specified format, as a dictionary. Here is an example implementation of the `get_pokemon_data` function: ```py...
10,038
[ { "from": "human", "value": "\n\nDesign a Python function `get_pokemon_data` that takes a JSON string representing a Pokémon's data and returns a dictionary with specific details about the Pokémon. The function should extract the following information:\n\n- `name`: The name of the Pokémon.\n- `types`: A lis...
Create a Python function `parse_feat_data` that takes a JSON string representing a feat from a role-playing game and extracts relevant information into a structured dictionary. The function should adhere to the following requirements: - The input JSON string will contain information about a feat, similar to the give...
```python import json def parse_feat_data(json_string): """ Parses a JSON string representing a feat and extracts relevant information. Parameters: - json_string (str): A JSON string representing a feat. Returns: - dict: A dictionary with extracted feat information or None if parsin...
To implement the `parse_feat_data` function based on your requirements, we need to ensure that it can parse a JSON string, extract specific fields, and handle errors gracefully. Below is the code for the function that meets these criteria. ```python import json def parse_feat_data(json_string): try: # Att...
10,039
[ { "from": "human", "value": "\n\nCreate a Python function `parse_feat_data` that takes a JSON string representing a feat from a role-playing game and extracts relevant information into a structured dictionary. The function should adhere to the following requirements:\n\n- The input JSON string will contain ...
You are tasked with creating a Python function that processes a JSON object representing a Common Vulnerabilities and Exposures (CVE) record. The function should extract and return a summary of the CVE, including its ID, state, description, affected product and version, and references. The JSON object follows a spec...
```python import json def summarize_cve_record(cve_record): """ Summarizes a CVE record by extracting the CVE ID, state, description, affected product and version, and references. Parameters: cve_record (dict): A JSON object representing a CVE record. Returns: dict: A dictionary contain...
To create a Python function that processes a JSON object representing a Common Vulnerabilities and Exposures (CVE) record, we need to extract several pieces of information from the specified structure. Below is an implementation of the `summarize_cve_record(cve_record)` function that fulfills the requirements you've ou...
10,040
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that processes a JSON object representing a Common Vulnerabilities and Exposures (CVE) record. The function should extract and return a summary of the CVE, including its ID, state, description, affected product and version, and ...
Create a Python function `parse_contract_summary` that extracts relevant information from a JSON object representing a public contract summary. The function should return a dictionary containing the following keys with their respective values extracted from the JSON: - `contract_id`: The identifier of the contract. -...
```python import json def parse_contract_summary(contract_json): """ Parses a JSON object representing a public contract summary and extracts relevant information. :param contract_json: A JSON object containing contract summary data. :return: A dictionary with extracted contract information. ...
To achieve the parsing of a JSON object representing a public contract summary, we can implement the function `parse_contract_summary` in Python. Below is a sample implementation of the function that extracts the specified information and handles errors appropriately: ```python def parse_contract_summary(contract_json...
10,041
[ { "from": "human", "value": "\nCreate a Python function `parse_contract_summary` that extracts relevant information from a JSON object representing a public contract summary. The function should return a dictionary containing the following keys with their respective values extracted from the JSON:\n\n- `con...
Write a Python program that reads a JSON configuration file and provides an interface to access the configuration settings. The JSON configuration file contains settings for a web application, including database connection strings, logging preferences, and external service URLs. The program should meet the following...
```python import json # Import the necessary packages def load_config(file_path): """ Load the JSON configuration from the specified file path. :param file_path: Path to the JSON configuration file. :return: A dictionary containing the configuration settings or None if an error occurs. """ ...
Here's a Python program that fulfills the specified requirements. This program reads a configuration file named `config.json`, provides functions to access specific configurations, and includes error handling for missing or invalid JSON files. ### config.json Example Before we delve into the code, here's an example o...
10,042
[ { "from": "human", "value": "\n\nWrite a Python program that reads a JSON configuration file and provides an interface to access the configuration settings. The JSON configuration file contains settings for a web application, including database connection strings, logging preferences, and external service U...
You are given a list of trending topics on a social media platform, each represented as a JSON object with the following properties: - `name`: The name of the trending topic. - `query`: The search query associated with the trending topic. - `rank`: The rank of the trending topic based on its current popularity. - `t...
```python import re def process_trending_topics(data): """ Processes a list of trending topics, converting tweet counts to integers and cleaning query strings. Parameters: - data (list): A list of dictionaries representing trending topics. Returns: - list: A list of dictionaries with proces...
Here's the implementation of the `process_trending_topics` function based on the requirements you've provided: ```python def process_trending_topics(data): """ Processes a list of trending topics, converting tweet counts to integers and cleaning query strings. Parameters: - data (list): A list of dict...
10,043
[ { "from": "human", "value": "\n\nYou are given a list of trending topics on a social media platform, each represented as a JSON object with the following properties:\n\n- `name`: The name of the trending topic.\n- `query`: The search query associated with the trending topic.\n- `rank`: The rank of the trend...
Write a Python function `extract_recipe_details(json_data)` that takes a JSON object representing a collection of recipe and breadcrumb data, and extracts the details of the recipe into a dictionary with the following keys: - `name`: The name of the recipe. - `url`: The URL of the main entity of the page. - `descrip...
```python import json def extract_recipe_details(json_data): """ Extracts details of the recipe from the given JSON data. :param json_data: A JSON object containing recipe and breadcrumb data. :return: A dictionary with extracted recipe details. """ for entry in json_data: if entry.g...
Here’s a Python function that extracts the required recipe details from a JSON object into a dictionary: ```python import json def extract_recipe_details(json_data): # Initialize an empty dictionary to hold the recipe details recipe_details = {} # Check if 'recipe' is in the JSON data if 'recipe'...
10,044
[ { "from": "human", "value": "\n\nWrite a Python function `extract_recipe_details(json_data)` that takes a JSON object representing a collection of recipe and breadcrumb data, and extracts the details of the recipe into a dictionary with the following keys:\n\n- `name`: The name of the recipe.\n- `url`: The ...
You are tasked with creating a Python function that can dynamically generate messages for a university's student module history tracking system. The system keeps a record of various events such as creation, update, and deletion of student module history entries. The messages are internationalized, meaning they can be...
```python import json def generate_message(action, param, locale_data): """ Generates a localized message for a given action and parameter based on the provided locale data. :param action: A string representing the action performed ('created', 'updated', 'deleted', 'delete_question'). :param param: ...
To implement the function `generate_message` that adheres to your specifications, we first need to ensure we have a structure for the `locale_data` parameter containing the necessary messages. Based on the actions specified (`created`, `updated`, `deleted`, and `delete_question`), we will create a function that selects...
10,045
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that can dynamically generate messages for a university's student module history tracking system. The system keeps a record of various events such as creation, update, and deletion of student module history entries. The messages...
Write a Python function `update_tsconfig_paths` that takes a JSON string representing a TypeScript configuration file (`tsconfig.json`) and a dictionary of path overrides. The function should update the `paths` property in the TypeScript configuration with the provided overrides, ensuring that the most specific paths...
```python import json from collections import defaultdict def update_tsconfig_paths(tsconfig_json, path_overrides): """ Updates the 'paths' property in the TypeScript configuration with the provided overrides. :param tsconfig_json: A JSON string representing a TypeScript configuration file. :param p...
Here is a solution for the `update_tsconfig_paths` function that meets the specified requirements. The function will read a JSON string, update the `paths` property according to the provided overrides, and return the updated JSON string while preserving formatting as much as possible. ```python import json import re ...
10,046
[ { "from": "human", "value": "\n\nWrite a Python function `update_tsconfig_paths` that takes a JSON string representing a TypeScript configuration file (`tsconfig.json`) and a dictionary of path overrides. The function should update the `paths` property in the TypeScript configuration with the provided overr...
You are tasked with creating a Python function `update_tsconfig_paths` that takes a JSON object representing a TypeScript configuration file (`tsconfig.json`) and a dictionary of path aliases. The function should update the `paths` property within the `compilerOptions` of the given JSON object with the provided path ...
```python import json def update_tsconfig_paths(tsconfig, path_aliases): """ Updates the 'paths' property within the 'compilerOptions' of a tsconfig JSON object. :param tsconfig: A dict representing the tsconfig.json file. :param path_aliases: A dict with string keys and list of string values for pa...
Based on your requirements, we can implement the `update_tsconfig_paths` function in Python. This function will modify the `tsconfig.json` JSON structure to include the specified path aliases within the `compilerOptions`. Here's how the implementation can look: ```python def update_tsconfig_paths(tsconfig: dict, path_...
10,047
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `update_tsconfig_paths` that takes a JSON object representing a TypeScript configuration file (`tsconfig.json`) and a dictionary of path aliases. The function should update the `paths` property within the `compilerOptions` of th...
Write a Python function `update_package_json` that takes a JSON string representing a `package.json` file (similar to the given code snippet) and a dictionary of updates. The function should apply the updates to the JSON string and return the updated JSON string. The updates can include changes to existing fields or ...
```python import json from collections import OrderedDict def update_package_json(json_string: str, updates: dict) -> str: """ Updates a package.json JSON string with the given updates. :param json_string: A string representation of a package.json file. :param updates: A dictionary containing the up...
To implement the function `update_package_json`, we will follow the specifications you provided. We will validate the JSON string, apply the updates while maintaining the order of fields, and handle any potential exceptions. Here's the implementation: ```python import json from collections import OrderedDict def upda...
10,048
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_json` that takes a JSON string representing a `package.json` file (similar to the given code snippet) and a dictionary of updates. The function should apply the updates to the JSON string and return the updated JSON string. The updates...
You are tasked with creating a Python script that will validate and update a JSON configuration for a software project. The JSON configuration contains various settings for the build process, packaging, and platform-specific options for a Tauri application. The script should perform the following tasks: 1. Validate...
```python import json from jsonschema import validate, ValidationError # Define the expected JSON schema schema = { "type": "object", "properties": { "build": { "type": "object", "properties": { "beforeDevCommand": {"type": "string"}, "beforeBui...
Here’s a Python script that accomplishes the tasks you outlined. This script uses the `json` module to handle JSON data and `jsonschema` to validate the JSON structure against a schema. Please note that you'll need to have the `jsonschema` library installed to run the validation. You can install it using pip: ```bash...
10,049
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python script that will validate and update a JSON configuration for a software project. The JSON configuration contains various settings for the build process, packaging, and platform-specific options for a Tauri application.\n\nThe script sho...
You are given a JSON object representing metadata about various legal documents, their types, references, attributes, and associated resources. Your task is to write a Python function `extract_document_details(json_data)` that takes this JSON object as input and extracts specific details about the documents, includin...
```python import json def extract_document_details(json_data): """ Extracts details about documents from the given JSON data. Parameters: json_data (dict): A JSON object containing metadata about legal documents. Returns: list: A list of dictionaries with keys 'uri', 'type', 'public...
To implement the `extract_document_details` function as per your requirements, we can use Python's `json` library to parse the JSON object and extract the desired details from it. Here is how the function can be constructed: ```python def extract_document_details(json_data): # Initialize an empty list to hold the ...
10,050
[ { "from": "human", "value": "\n\nYou are given a JSON object representing metadata about various legal documents, their types, references, attributes, and associated resources. Your task is to write a Python function `extract_document_details(json_data)` that takes this JSON object as input and extracts spe...
You are tasked with creating a Python function `update_debug_configuration` that takes a JSON string representing a debug configuration for a development environment and updates it according to the following rules: 1. If the configuration is of type "chrome" and the request is "launch", update the `url` to a new URL...
```python import json def update_debug_configuration(json_config: str, new_url: str, new_port: int) -> str: try: config = json.loads(json_config) for conf in config['configurations']: if conf['type'] == 'chrome': if conf['request'] == 'launch': conf...
Here is a Python function that meets the requirements specified in your prompt. It updates a JSON string representing debug configurations based on whether the configurations are for launching or attaching Chrome. ```python import json def update_debug_configuration(json_config: str, new_url: str, new_port: int) -> s...
10,051
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `update_debug_configuration` that takes a JSON string representing a debug configuration for a development environment and updates it according to the following rules:\n\n1. If the configuration is of type \"chrome\" and the req...
Create a Python function `validate_mod_metadata` that takes a JSON string representing the metadata of a Minecraft mod and validates it against a set of rules. The function should return a dictionary with a `valid` key indicating if the metadata is valid (`True` or `False`), and an `errors` key containing a list of s...
```python import json import re def validate_mod_metadata(json_string): """ Validates the metadata of a Minecraft mod provided as a JSON string. Parameters: - json_string: A string containing the JSON representation of the mod metadata. Returns: A dictionary with two keys: - val...
Here's a Python function `validate_mod_metadata` that checks the mod metadata against the specified validation rules. This function utilizes the `json` module to parse the metadata and validate its fields according to the given criteria. ```python import json import re def validate_mod_metadata(json_string): erro...
10,052
[ { "from": "human", "value": "\n\nCreate a Python function `validate_mod_metadata` that takes a JSON string representing the metadata of a Minecraft mod and validates it against a set of rules. The function should return a dictionary with a `valid` key indicating if the metadata is valid (`True` or `False`),...
You are tasked with creating a Python function `analyze_package_data` that processes JSON data representing metadata about a software package and its files. The function should take a JSON string as input and return a dictionary with specific details extracted and calculated from the input data. The function should ...
```python import json def analyze_package_data(json_data): """ Analyze package data from a JSON string and return a dictionary with specific details. :param json_data: A JSON string containing package metadata. :return: A dictionary with total SLOC, text file status, owner read permission, file exte...
Here’s a Python function `analyze_package_data` that fulfills your requirements. This function will take a JSON string as input, process it, and return the desired output as a dictionary. ```python import json def analyze_package_data(json_data): # Parse the JSON string data = json.loads(json_data) #...
10,053
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `analyze_package_data` that processes JSON data representing metadata about a software package and its files. The function should take a JSON string as input and return a dictionary with specific details extracted and calculated...
Design a Python function named `analyze_petition_status` that takes a JSON string representing a petition's data and returns a dictionary with the petition's status, signature count, and a boolean indicating whether the petition was ever opened for debate. The function should follow these specifications: 1. The inp...
```python import json def analyze_petition_status(json_data): """ Analyzes the status of a petition from a JSON string. Parameters: - json_data (str): A JSON string representing the petition's data. Returns: - dict: A dictionary with the petition's status, signature count, and a boolean ind...
To implement the `analyze_petition_status` function, we will parse the JSON string, extract the necessary fields, and return them in the specified dictionary format. If the input format is incorrect or the expected fields are missing, we will raise a `ValueError` with an appropriate message. Here's how you can impleme...
10,054
[ { "from": "human", "value": "\n\nDesign a Python function named `analyze_petition_status` that takes a JSON string representing a petition's data and returns a dictionary with the petition's status, signature count, and a boolean indicating whether the petition was ever opened for debate.\n\nThe function sh...
You are tasked with writing a Python function that processes a JSON object representing a collection of image metadata. The JSON object has a structure similar to the given code snippet. Your function should validate the JSON object and add a default filename to any image entry that does not have a 'filename' key. Th...
```python import json def add_default_filenames(json_data): """ Adds default filenames to the image entries in the JSON object that are missing the 'filename' key. :param json_data: A JSON object (as a Python dictionary) containing image metadata. :return: The modified JSON object with default f...
You can implement the `add_default_filenames` function in Python as per the requirements specified. The function iterates through the list of image dictionaries, checks for the presence of the 'filename' key, and adds a default filename based on the 'idiom' and 'scale' keys if the 'filename' is missing. Below is the im...
10,055
[ { "from": "human", "value": "\n\nYou are tasked with writing a Python function that processes a JSON object representing a collection of image metadata. The JSON object has a structure similar to the given code snippet. Your function should validate the JSON object and add a default filename to any image en...
Write a Python function `validate_package_json` that takes a string representing a JSON object similar to the given code snippet. The function should check if the JSON object is a valid representation of a `package.json` file used in Node.js projects. The validation should cover the following rules: 1. The `name` fi...
```python import json import re from urllib.parse import urlparse def validate_package_json(json_str): """ Validates a JSON string representing a package.json file. Parameters: json_str (str): A string representation of a package.json JSON object. Returns: tuple: A tuple containing a boolea...
To create a function that validates a JSON object representing a `package.json` file according to the specified rules, we can use the `json` module for parsing the JSON string and define validation helpers for each condition. Here’s how the function can be implemented: ```python import json import re from urllib.parse...
10,056
[ { "from": "human", "value": "\n\nWrite a Python function `validate_package_json` that takes a string representing a JSON object similar to the given code snippet. The function should check if the JSON object is a valid representation of a `package.json` file used in Node.js projects. The validation should c...
You are tasked with creating a Python function that processes a JSON object representing a paginated list of educational videos. The JSON object contains information about the current page, page size, a list of video items, the total number of pages, and the total number of results. Each video item includes a unique...
```python import json def generate_video_summary(page_data): """ Generates a summary report for a paginated list of educational videos. Args: page_data (dict): A JSON object containing paginated video data. Returns: dict: A dictionary with the following structure: { 'tot...
Here's a Python function named `generate_video_summary` that processes a JSON object representing a paginated list of educational videos and generates the required summary report. ```python import json def generate_video_summary(json_data): # Parse the JSON data if it's in string format if isinstance(json_dat...
10,057
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that processes a JSON object representing a paginated list of educational videos. The JSON object contains information about the current page, page size, a list of video items, the total number of pages, and the total number of ...
You are tasked with creating a Python function that can parse a JSON object representing a database schema and generate a list of SQL `CREATE TABLE` statements based on the schema. The JSON object contains information about the database version, identity hash, entities (tables), and setup queries. Each entity include...
```python import json def generate_sql_statements(json_schema): """ Parses a JSON object representing a database schema and generates a list of SQL CREATE TABLE statements. :param json_schema: JSON object containing the database schema :return: List of SQL CREATE TABLE statements """ sql...
To create a Python function that parses a JSON schema and generates corresponding SQL `CREATE TABLE` statements, we need to focus on extracting the relevant information from the JSON structure. Here's how we can implement the function `generate_sql_statements`: 1. Read the input JSON schema. 2. Extract each entity (ta...
10,058
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that can parse a JSON object representing a database schema and generate a list of SQL `CREATE TABLE` statements based on the schema. The JSON object contains information about the database version, identity hash, entities (tabl...
Write a Python function `validate_package_json` that takes a JSON string representing a package.json file (commonly found in Node.js projects) and checks for the following conditions: 1. The `name` field must be a non-empty string. 2. The `version` field must be a non-empty string and follow semantic versioning. 3. ...
```python import json import re import semver def validate_package_json(json_string): """ Validates the given package.json content in JSON string format. :param json_string: A string containing the package.json content. :return: A dictionary with condition numbers as keys and boolean values indi...
To implement the `validate_package_json` function, we can use the `json` module for parsing the JSON string, and regular expressions for validating the version strings and URLs. Below is a complete function that checks each of the specified conditions and returns a dictionary with the results. ```python import json im...
10,059
[ { "from": "human", "value": "\n\nWrite a Python function `validate_package_json` that takes a JSON string representing a package.json file (commonly found in Node.js projects) and checks for the following conditions:\n\n1. The `name` field must be a non-empty string.\n2. The `version` field must be a non-em...
You are tasked with creating a Python function `parse_cve_details` that takes a JSON string representing a CVE (Common Vulnerabilities and Exposures) record and extracts specific details about the vulnerability. The function should return a dictionary with the following keys and their corresponding values extracted f...
```python import json def parse_cve_details(cve_json): """ Parses a JSON string representing a CVE record and extracts specific details. :param cve_json: JSON string representing a CVE record. :return: Dictionary with extracted details. :raises ValueError: If required information is missing ...
To implement the `parse_cve_details` function as specified, we will need to parse a JSON string and extract the necessary fields into a structured dictionary format. Below is the Python code for the function, including error handling to ensure that all required information is present. ```python import json def parse_...
10,060
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `parse_cve_details` that takes a JSON string representing a CVE (Common Vulnerabilities and Exposures) record and extracts specific details about the vulnerability. The function should return a dictionary with the following keys...
You are tasked with writing a Python function that processes a JSON object representing a collection of image metadata. The JSON object has a structure similar to the given code snippet. Your function should validate the JSON object and perform the following operations: 1. Ensure that each image entry has a 'filenam...
```python import json def clean_image_metadata(json_obj): """ Cleans the image metadata JSON object by removing entries that do not have all required keys: 'filename', 'idiom', and 'scale'. Parameters: json_obj (dict): A JSON object containing image metadata. Returns: dict: A new JSON o...
To accomplish the task of cleaning image metadata from a JSON object according to the specified requirements, we can define a Python function `clean_image_metadata`. Below is the implementation of the function along with some test cases to verify its correctness. ```python import json def clean_image_metadata(json_ob...
10,061
[ { "from": "human", "value": "\n\nYou are tasked with writing a Python function that processes a JSON object representing a collection of image metadata. The JSON object has a structure similar to the given code snippet. Your function should validate the JSON object and perform the following operations:\n\n1...
Write a Python function `parse_package_info` that takes a JSON string representing a package information similar to the given code snippet and returns a dictionary with specific details about the package. The function should extract the following information: - Package name - Package version - List of contributors (ju...
```python import json def parse_package_info(json_string: str) -> dict: """ Parses a JSON string containing package information and extracts specific details. Parameters: - json_string (str): A JSON string representing package information. Returns: - dict: A dictionary with the extracted pac...
To implement the `parse_package_info` function, we will use Python's built-in `json` module to parse the JSON string. We will then extract the specified fields, ensuring to handle cases where certain fields might be missing. Here's the implementation of the function: ```python import json from typing import Optional...
10,062
[ { "from": "human", "value": "\nWrite a Python function `parse_package_info` that takes a JSON string representing a package information similar to the given code snippet and returns a dictionary with specific details about the package. The function should extract the following information:\n- Package name\n...
Write a Python program that processes a JSON object representing software package information and performs the following tasks: 1. Extracts the name, version, and description of the software. 2. Checks if the software is outdated. 3. Determines if the software has any dependencies on the macOS version and returns th...
```python import json def process_software_info(json_data): """ Processes a JSON object representing software package information and extracts relevant details such as name, version, description, outdated status, macOS dependencies, and uninstall paths. :param json_data: JSON object as a str...
Here's a Python program that meets your requirements. The program includes the `process_software_info` function that processes a JSON object representing software package information, performing the specified tasks. ```python import json def process_software_info(json_data): # If the input is a JSON string, parse...
10,063
[ { "from": "human", "value": "\n\nWrite a Python program that processes a JSON object representing software package information and performs the following tasks:\n\n1. Extracts the name, version, and description of the software.\n2. Checks if the software is outdated.\n3. Determines if the software has any d...
You are tasked with writing a Python function that analyzes tracking data for different domains. The function should take a JSON string representing tracking data for a domain and return a summary of the tracking statistics. The summary should include the following information: - The domain name. - The total number ...
```python import json def analyze_tracking_data(json_data: str) -> dict: """ Analyzes tracking data for a domain from a JSON string and returns a summary. Parameters: - json_data (str): A JSON string containing tracking data for a domain. Returns: - dict: A dictionary containing the summary...
To create the `analyze_tracking_data` function as per your requirements, we can follow these steps: 1. Parse the JSON string to extract relevant tracking data. 2. Perform calculations to determine the total number of sites, count subdomains, track prevalence, identify the types of tracking scripts, and collect example...
10,064
[ { "from": "human", "value": "\n\nYou are tasked with writing a Python function that analyzes tracking data for different domains. The function should take a JSON string representing tracking data for a domain and return a summary of the tracking statistics.\n\nThe summary should include the following inform...
Design a Python program that simulates the backend logic for a currency conversion API based on the provided JSON OpenAPI specification. The program should include the following functionalities: 1. User registration with unique email validation. 2. User login that returns a mock authentication token. 3. Currency conv...
```python import json from flask import Flask, request, jsonify app = Flask(__name__) # Mock database users = {} transactions = [] auth_tokens = {} # Conversion rates conversion_rates = { 'USD': {'BRL': 5, 'EUR': 1/1.2, 'JPY': 1/0.0091}, 'BRL': {'USD': 1/5, 'EUR': 1/5*1.2, 'JPY': 1/5*0.0091}, 'EUR': {'U...
Below is a Python program that simulates a currency conversion API backend based on the specified requirements. The program covers user registration, login, currency conversion, and transaction history retrieval, including error handling for invalid cases. To keep things simple, I will use in-memory storage for user d...
10,065
[ { "from": "human", "value": "\nDesign a Python program that simulates the backend logic for a currency conversion API based on the provided JSON OpenAPI specification. The program should include the following functionalities:\n\n1. User registration with unique email validation.\n2. User login that returns ...
Write a Python function `extract_meaning` that takes a JSON string representing a dictionary entry as input and extracts the meaning of the word in a specific format. The JSON structure is similar to the given code snippet, where the word's etymological information is provided, including its grammatical forms and the...
```python import json from typing import List, Tuple def extract_meaning(json_string: str) -> List[Tuple[str, List[str]]]: """ Extracts the meanings of a word from a JSON string representing a dictionary entry. :param json_string: A JSON string representing a dictionary entry. :return: A list of tup...
To implement the `extract_meaning` function as specified, we'll need to parse the JSON string, ensure it adheres to the expected structure, and then extract the grammatical forms along with their meanings. Below is how you can accomplish this in Python: ```python import json from typing import List, Tuple def extract...
10,066
[ { "from": "human", "value": "\n\nWrite a Python function `extract_meaning` that takes a JSON string representing a dictionary entry as input and extracts the meaning of the word in a specific format. The JSON structure is similar to the given code snippet, where the word's etymological information is provid...
You are tasked with writing a Python function that processes a list of security group configurations for a cloud infrastructure (as provided in the given code snippet) and generates a report of the security groups that allow unrestricted outbound access (i.e., access to `0.0.0.0/0`). The report should include the `Gr...
```python import json def generate_unrestricted_outbound_report(security_groups): """ Generates a report of security groups that allow unrestricted outbound access. :param security_groups: A list of dictionaries representing security group configurations. :return: A list of dictionaries with 'GroupI...
To create the function `generate_unrestricted_outbound_report`, we will iterate through the list of security group configurations and check each security group's outbound rules. Specifically, we will look for any egress permission that meets the criteria for allowing unrestricted outbound access. Below is the implement...
10,067
[ { "from": "human", "value": "\n\nYou are tasked with writing a Python function that processes a list of security group configurations for a cloud infrastructure (as provided in the given code snippet) and generates a report of the security groups that allow unrestricted outbound access (i.e., access to `0.0...
Write a Python function `validate_package_json` that takes a JSON string representing a package configuration (similar to the one provided in the code snippet) and validates it against the following rules: 1. The `name` field must be present and must be a non-empty string. 2. The `type` field must be present and mus...
```python import json def validate_package_json(json_string): """ Validates a package configuration JSON string against predefined rules. :param json_string: A JSON string representing a package configuration. :return: True if the JSON string is valid, otherwise raises a ValueError. """ # Lo...
Certainly! Here's a Python function `validate_package_json` that validates a JSON string according to the specified rules. ```python import json def validate_package_json(package_json_str): # Parse the JSON string try: package_json = json.loads(package_json_str) except json.JSONDecodeError as e: ...
10,068
[ { "from": "human", "value": "\n\nWrite a Python function `validate_package_json` that takes a JSON string representing a package configuration (similar to the one provided in the code snippet) and validates it against the following rules:\n\n1. The `name` field must be present and must be a non-empty string...
Write a Python program that processes a JSON object representing a security advisory for a software vulnerability. The JSON object contains various details about the vulnerability, including its schema version, unique identifier, modification and publication dates, aliases, a detailed description, severity, affected ...
```python import json from datetime import datetime # Given JSON string json_str = '''{ "schema_version": "1.3.0", "id": "GHSA-7rhm-jv98-85qw", "modified": "2022-05-02T00:10:40Z", "published": "2022-05-02T00:10:40Z", "aliases": [ "CVE-2008-4503" ], "details": "The Settings Manager in Adobe Flash Pl...
Here’s a Python program that meets the requirements you've outlined. I will include necessary import statements, a sample JSON object, the functionalities to extract information, generate a report, add references, and mark the vulnerability as reviewed on GitHub. ```python import json from datetime import datetime # ...
10,069
[ { "from": "human", "value": "\n\nWrite a Python program that processes a JSON object representing a security advisory for a software vulnerability. The JSON object contains various details about the vulnerability, including its schema version, unique identifier, modification and publication dates, aliases, ...
Design a Python function `extract_vulnerability_details` that takes a JSON object representing a CVE (Common Vulnerabilities and Exposures) record and extracts key details about the vulnerability. The function should return a dictionary with the following structure: ```python { "cve_id": "CVE-2021-21817", "ve...
```python import json def extract_vulnerability_details(cve_record): """ Extracts key details from a CVE record JSON object. Parameters: cve_record (dict): A dictionary representing a CVE record. Returns: dict: A dictionary containing extracted vulnerability details. """ # Initializ...
Here is a Python function `extract_vulnerability_details` which takes a JSON object representing a CVE record. This function extracts key details about the vulnerability and returns the specified structure. If any of the desired fields are missing, it sets the value to `None`. ```python import json def extract_vulner...
10,070
[ { "from": "human", "value": "\nDesign a Python function `extract_vulnerability_details` that takes a JSON object representing a CVE (Common Vulnerabilities and Exposures) record and extracts key details about the vulnerability. The function should return a dictionary with the following structure:\n\n```pyth...
You are tasked with creating a Python function that processes a JSON object representing a Common Vulnerabilities and Exposures (CVE) entry. The function should extract and return a summary of the CVE, including its ID, description, severity, and a list of affected products and versions. The summary should be return...
```python import json def extract_cve_summary(cve_data): """ Extracts a summary of the CVE from the provided JSON data. Parameters: cve_data (dict): A dictionary representing the CVE JSON data. Returns: dict: A dictionary containing the CVE ID, description, severity, and a list of affected ...
To create a Python function that processes a JSON object representing a CVE entry and extracts the required summary, we will define a function called `extract_cve_summary`. This function will take a JSON object as input, extract the necessary fields, and format them accordingly. Here's how you might implement this: ``...
10,071
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that processes a JSON object representing a Common Vulnerabilities and Exposures (CVE) entry. The function should extract and return a summary of the CVE, including its ID, description, severity, and a list of affected products ...
You are tasked with creating a function `validate_product_json` that takes a JSON string representing a product configuration and validates it against a set of rules. The JSON structure is similar to the given code snippet, which represents a product with various fields and references. The validation rules are as fo...
```python import json def validate_product_json(json_string): """ Validates a product configuration JSON string against specific rules. :param json_string: A JSON string representing a product configuration. :return: A tuple (is_valid, errors) where is_valid is a boolean indicating ...
To create the `validate_product_json` function according to the specified requirements, we need to follow a systematic process to parse the JSON string, check each validation rule, and gather any errors encountered during the validation process. Below is a Python implementation of the function: ```python import json ...
10,072
[ { "from": "human", "value": "\n\nYou are tasked with creating a function `validate_product_json` that takes a JSON string representing a product configuration and validates it against a set of rules. The JSON structure is similar to the given code snippet, which represents a product with various fields and ...
Write a Python program that reads a JSON object representing a package configuration for a software project and performs the following tasks: 1. Validates the JSON object against the following rules: - The `name` field must be a non-empty string. - The `version` field must follow semantic versioning (e.g., `1....
```python import json import re # Importing required packages from jsonschema import validate from jsonschema.exceptions import ValidationError # Define the JSON schema for validation schema = { "type": "object", "properties": { "name": {"type": "string", "minLength": 1}, "version": {"type":...
Below is a Python program that performs the tasks you've specified. It reads a JSON object representing package configuration, validates it according to the rules you've provided, and either confirms its validity or raises exceptions for any violations. ```python import json import re class PackageValidationError(Exc...
10,073
[ { "from": "human", "value": "\n\nWrite a Python program that reads a JSON object representing a package configuration for a software project and performs the following tasks:\n\n1. Validates the JSON object against the following rules:\n - The `name` field must be a non-empty string.\n - The `version` f...
Write a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and updates it according to the following rules: 1. If the `private` field is `true`, add a new field `license` with the value `"UNLICENSED"`. 2. Increment the patch version n...
```python import json def update_package_json(json_str): """ Updates the given package.json string according to the specified rules and returns the updated JSON string. :param json_str: A string representation of a package.json file. :return: An updated JSON string with the changes applied. ...
Here's a Python function `update_package_json` that accomplishes the requirements you specified: ```python import json import re def update_package_json(package_json_str): # Parse the JSON string package_data = json.loads(package_json_str) # Rule 1: If the private field is true, add license field as ...
10,074
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and updates it according to the following rules:\n\n1. If the `private` field is `true`, add a new field `license` with the value `\"...
Design a function `transform_fanfiction_metadata` that takes a JSON string representing the metadata of a fanfiction story and returns a dictionary with specific transformations applied to the data. The function should adhere to the following requirements: 1. The `id` should be converted to an integer. 2. The `publi...
```python import json from datetime import datetime def transform_fanfiction_metadata(json_string): """ Transforms the metadata of a fanfiction story from a JSON string to a dictionary with specific fields altered. Parameters: - json_string (str): A JSON string representing the metadata of a fanfict...
To implement the `transform_fanfiction_metadata` function according to the specified requirements, we will take the following steps: 1. Parse the input JSON string into a Python dictionary. 2. Apply the specified transformations to the extracted fields. 3. Return a new dictionary containing the transformed data. Assu...
10,075
[ { "from": "human", "value": "\n\nDesign a function `transform_fanfiction_metadata` that takes a JSON string representing the metadata of a fanfiction story and returns a dictionary with specific transformations applied to the data. The function should adhere to the following requirements:\n\n1. The `id` sho...
Write a Python function `update_package_version(package_json, package_name, new_version)` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects), the name of a dependency package, and a new version number. The function should update the version of the specified package in the ...
```python import json def update_package_version(package_json, package_name, new_version): """ Updates the version of a specified package in the dependencies of a package.json string. :param package_json: A string in JSON format representing a package.json file. :param package_name: The name of ...
To create the `update_package_version` function as described, we will follow these steps: 1. Parse the input JSON string to a Python dictionary. 2. Check if the specified package exists in the `dependencies`. 3. If it does, update its version to the new version specified. 4. Convert the dictionary back to a JSON strin...
10,076
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_version(package_json, package_name, new_version)` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects), the name of a dependency package, and a new version number. The function should update t...
Create a Python function named `extract_artwork_details` that takes a JSON string representing an artwork's information and extracts specific details about the artwork. The function should return a dictionary containing the following keys and their corresponding values from the JSON data: - `title`: The title of the...
```python import json def extract_artwork_details(json_data): """ Extracts details from a JSON string representing an artwork's information. Parameters: - json_data (str): A JSON string containing the artwork's information. Returns: - dict: A dictionary with specific details about t...
You can create the `extract_artwork_details` function using the built-in `json` module in Python to parse the JSON string and extract the required details. Here's an example of how you could implement this function: ```python import json def extract_artwork_details(json_string): # Parse the JSON string try: ...
10,077
[ { "from": "human", "value": "\n\nCreate a Python function named `extract_artwork_details` that takes a JSON string representing an artwork's information and extracts specific details about the artwork. The function should return a dictionary containing the following keys and their corresponding values from ...
You are tasked with creating a Python function `validate_plant_data` that takes a JSON string representing the configuration of a plant in a mystical agriculture system and validates it against a set of rules. The function should check the following: 1. The `enabled` field must be a boolean. 2. The `id` field must b...
```python import json def validate_plant_data(json_data): """ Validates the plant configuration data in JSON format. Parameters: - json_data (str): A JSON string representing the plant configuration. Returns: - bool: True if the validation passes, otherwise raises a ValueError. Raises:...
To create the `validate_plant_data` function that checks the structure of a JSON string representing a plant's configuration, we can follow the rules provided. We will use the `json` module to parse the JSON string and then apply the validation checks. The function will raise `ValueError` with a specific error message ...
10,078
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `validate_plant_data` that takes a JSON string representing the configuration of a plant in a mystical agriculture system and validates it against a set of rules. The function should check the following:\n\n1. The `enabled` fiel...
Create a Python function `extract_metadata` that takes a JSON object representing a IIIF manifest and extracts specific metadata about a historical map. The function should return a dictionary with the following keys and their corresponding values from the manifest: - `inventory_number`: The inventory number of the ...
```python import json def extract_metadata(manifest): """ Extracts specific metadata from a IIIF manifest JSON object. Parameters: manifest (dict): A dictionary representing a IIIF manifest. Returns: dict: A dictionary containing extracted metadata. """ metadata_dict = { 'in...
Certainly! Below is a Python function called `extract_metadata` that extracts specific metadata from a given IIIF manifest represented as a JSON object. The function will return a dictionary with the specified keys and their corresponding values. If any metadata is missing, it will return `None` for those fields. Here...
10,079
[ { "from": "human", "value": "\n\nCreate a Python function `extract_metadata` that takes a JSON object representing a IIIF manifest and extracts specific metadata about a historical map. The function should return a dictionary with the following keys and their corresponding values from the manifest:\n\n- `in...
Write a Python function `analyze_library_changes` that takes a JSON string representing a list of changes between two versions of a library and returns a dictionary summarizing the changes. Each change record in the JSON string contains information about the method calls that were added, updated, or removed between tw...
```python import json def analyze_library_changes(json_data): """ Analyzes the changes between two versions of a library from a JSON string. :param json_data: A JSON string representing a list of changes between two library versions. :return: A dictionary summarizing the changes with keys 'added', 'u...
To achieve the functionality you've described, we need to parse a JSON string containing information about changes in a library and construct a summary based on the types of changes: added, updated, and removed. Here’s how we can implement the `analyze_library_changes` function in Python: ```python import json def a...
10,080
[ { "from": "human", "value": "\nWrite a Python function `analyze_library_changes` that takes a JSON string representing a list of changes between two versions of a library and returns a dictionary summarizing the changes. Each change record in the JSON string contains information about the method calls that ...
You are tasked with creating a Python function `token_info_extractor` that takes a JSON string representing a cryptocurrency token's information and extracts specific details into a more concise dictionary. The function should adhere to the following requirements: 1. The function should parse the JSON string and ext...
```python import json def token_info_extractor(json_string): """ Extracts specific information from a JSON string representing a cryptocurrency token. Parameters: - json_string (str): A JSON string containing the token information. Returns: - dict: A dictionary with extracted token informat...
Sure! Below is the Python function `token_info_extractor` that meets the specified requirements. Additionally, I've included some test cases to verify the functionality of the function. ```python import json def token_info_extractor(json_string): # Parse the JSON string try: data = json.loads(json_str...
10,081
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function `token_info_extractor` that takes a JSON string representing a cryptocurrency token's information and extracts specific details into a more concise dictionary. The function should adhere to the following requirements:\n\n1. The ...
Write a Python function `generate_tsconfig` that creates a TypeScript configuration object with customizable options. The function should take the following parameters with default values: - `outDir` (default: `"./dist/"`): The directory where the compiled JavaScript files will be placed. - `sourceMap` (default: `Tr...
```python import json def generate_tsconfig(outDir="./dist/", sourceMap=True, noImplicitAny=True, module="ES2022", target="es6", jsx="react", moduleResolution="Node", allowSyntheticDefaultImports=True): """ Generates a TypeScript configuration object with customizable compiler options. ...
You can create the `generate_tsconfig` function as requested using Python. This function would return a dictionary that mimics the structure of a TypeScript `tsconfig.json` configuration file. Below is the implementation of the function: ```python def generate_tsconfig(outDir="./dist/", sourceMap=True, noImplicitAny=T...
10,082
[ { "from": "human", "value": "\n\nWrite a Python function `generate_tsconfig` that creates a TypeScript configuration object with customizable options. The function should take the following parameters with default values:\n\n- `outDir` (default: `\"./dist/\"`): The directory where the compiled JavaScript fi...
Design a function `filter_pokemon_data` that takes a JSON object representing a Pokémon's data and filters out specific fields based on a list of keys to keep. The function should return a new JSON object that only contains the keys specified in the list, preserving the structure of the original data. If a key in the...
```python import json def filter_pokemon_data(pokemon_data: dict, keys_to_keep: list) -> dict: """ Filters the given Pokémon data to only include the specified keys. :param pokemon_data: A dictionary containing Pokémon data. :param keys_to_keep: A list of strings representing the keys to keep in the...
Here's a Python function `filter_pokemon_data` that meets the requirements outlined in your request. The function takes a dictionary representing Pokémon data and a list of keys to keep, then returns a new dictionary containing only those specified keys: ```python def filter_pokemon_data(pokemon_data: dict, keys_to_ke...
10,083
[ { "from": "human", "value": "\n\nDesign a function `filter_pokemon_data` that takes a JSON object representing a Pokémon's data and filters out specific fields based on a list of keys to keep. The function should return a new JSON object that only contains the keys specified in the list, preserving the stru...
You are tasked with creating a function `calculate_total_cost` that takes a JSON object representing an order and calculates the total cost of the order including the item price and any additional charges. The JSON object follows the structure provided in the given code snippet. The function should: - Extract the pr...
```python import json def calculate_total_cost(order_json): """ Calculate the total cost of an order from a JSON object. :param order_json: A JSON object representing an order. :return: The total cost as a float. """ total_cost = 0.0 for item in order_json['message']['order']['quote']['b...
To implement the `calculate_total_cost` function, we need to extract the prices from the `quote.breakup` list in the JSON structure and sum them up. We will write a function that processes this structure and returns the total cost. Below is the Python code for the function based on your requirements: ```python def ca...
10,084
[ { "from": "human", "value": "\n\nYou are tasked with creating a function `calculate_total_cost` that takes a JSON object representing an order and calculates the total cost of the order including the item price and any additional charges. The JSON object follows the structure provided in the given code snip...
You are tasked with creating a Python function that processes a JSON object representing the build metadata of an Android application. The JSON object contains information about the build version, artifact type, application ID, variant name, and details about the build elements. Write a function `process_build_metad...
```python import json def process_build_metadata(json_string): """ Processes a JSON string containing build metadata and extracts specific fields. Parameters: - json_string (str): A JSON string representing the build metadata. Returns: - dict: A dictionary with extracted metadata fields. ...
To implement the `process_build_metadata` function as described, we can use the `json` module in Python to parse the JSON string. We will extract the required fields and handle any potential errors that may arise from invalid JSON or missing fields. Here is how you can write this function: ```python import json def p...
10,085
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that processes a JSON object representing the build metadata of an Android application. The JSON object contains information about the build version, artifact type, application ID, variant name, and details about the build eleme...
Create a Python function `parse_api_endpoints` that takes a JSON string representing a Postman collection and extracts information about each API endpoint within the collection. The function should return a list of dictionaries, where each dictionary contains the following details about an endpoint: - `name`: The na...
```python import json def parse_api_endpoints(json_string, variables): """ Parses a JSON string representing a Postman collection and extracts information about each API endpoint within the collection. :param json_string: A JSON string representing a Postman collection. :param variables: A dicti...
To implement the `parse_api_endpoints` function, we will parse the JSON string to extract the necessary details about each API endpoint. We'll handle the placeholders in the URL using a dictionary of variables. Here's how the function could be structured: ```python import json def parse_api_endpoints(json_string, var...
10,086
[ { "from": "human", "value": "\n\nCreate a Python function `parse_api_endpoints` that takes a JSON string representing a Postman collection and extracts information about each API endpoint within the collection. The function should return a list of dictionaries, where each dictionary contains the following d...
Write a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and updates it according to the following rules: 1. If the `version` field exists, increment the minor version by 1 (e.g., 1.0.0 becomes 1.1.0). 2. If the `description` field i...
```python import json from packaging import version def update_package_json(json_str): """ Updates the given package.json string according to predefined rules. Parameters: - json_str: A string representation of a package.json file. Returns: - A string representation of the updated pa...
To create the `update_package_json` function based on your requirements, we can start by parsing the JSON string into a Python dictionary, manipulate it according to the rules you provided, and then convert it back to a JSON string. Below is an implementation of the function: ```python import json import re def updat...
10,087
[ { "from": "human", "value": "\nWrite a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and updates it according to the following rules:\n\n1. If the `version` field exists, increment the minor version by 1 (e.g., 1.0.0 bec...
You are tasked with creating a Python script that can analyze a given `package.json` file (commonly used in JavaScript and TypeScript projects) and perform the following operations: 1. List all the dependencies and their versions. 2. List all the devDependencies and their versions. 3. Check if a given dependency is ...
```python import json class PackageJsonAnalyzer: """ A class to analyze package.json contents and provide information about dependencies, devDependencies, and scripts. """ def __init__(self, package_json): self.data = json.loads(package_json) def list_dependencies(self): ...
Here's a Python script that implements the `PackageJsonAnalyzer` class according to your specifications. This script uses the `json` library to parse the content of a `package.json` file. ```python import json class PackageJsonAnalyzer: def __init__(self, package_json): """Initialize the analyzer with the...
10,088
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python script that can analyze a given `package.json` file (commonly used in JavaScript and TypeScript projects) and perform the following operations:\n\n1. List all the dependencies and their versions.\n2. List all the devDependencies and thei...
Write a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and a dictionary of updates. The function should apply the updates to the JSON string and return the updated JSON string. The updates can include changes to existing fields, ad...
```python import json def update_package_json(package_json_str, updates): """ Updates a package.json string with the given updates. :param package_json_str: A string representation of a package.json file. :param updates: A dictionary containing the updates to be applied. :return: An updated pack...
You can implement the `update_package_json` function to apply the specified updates to the `package.json` JSON string while preserving the order of the fields. Here's one way to do this using the `json` module along with `collections.OrderedDict` to maintain the original order of keys: ```python import json from colle...
10,089
[ { "from": "human", "value": "\n\nWrite a Python function `update_package_json` that takes a JSON string representing a `package.json` file (commonly used in Node.js projects) and a dictionary of updates. The function should apply the updates to the JSON string and return the updated JSON string. The updates...
Write a Python function `parse_project_details(json_string)` that takes a JSON string representing a project configuration and extracts specific details about the project. The function should return a dictionary with the following keys and their corresponding values extracted from the JSON: - `format_version`: The f...
```python import json def parse_project_details(json_string): """ Parses a JSON string representing a project configuration and extracts specific details. Parameters: json_string (str): A JSON string representing the project configuration. Returns: dict: A dictionary with keys 'form...
To create a function `parse_project_details(json_string)` that extracts the specified project details from a JSON string, you'll want to use Python's built-in `json` library to parse the JSON string into a dictionary. After parsing, you can access the desired keys and construct a new dictionary containing the required ...
10,090
[ { "from": "human", "value": "\n\nWrite a Python function `parse_project_details(json_string)` that takes a JSON string representing a project configuration and extracts specific details about the project. The function should return a dictionary with the following keys and their corresponding values extracte...
You are given a JSON object representing metadata for images stored in a museum's digital archive. The JSON object contains information about different versions of an image (preview, original, and large), including their dimensions, format, modification timestamp, and location URLs. Your task is to write a Python fun...
```python import json def extract_image_info(json_data): """ Extracts image metadata from a JSON object and returns a simplified dictionary. :param json_data: JSON object containing image metadata :return: Dictionary with extracted image information """ data = json_data['data'] image...
To implement the function `extract_image_info`, we will need to navigate through the structure of the input JSON object to extract the relevant details regarding image metadata, including information for the preview, original, and large images. Here's how you can implement that function in Python: ```python def extra...
10,091
[ { "from": "human", "value": "\n\nYou are given a JSON object representing metadata for images stored in a museum's digital archive. The JSON object contains information about different versions of an image (preview, original, and large), including their dimensions, format, modification timestamp, and locati...
Write a Python function `extract_band_info` that takes a JSON object representing a satellite image metadata (following the structure of the given code snippet) and returns a dictionary containing the band information for each asset. The dictionary should have the asset keys as its keys and a list of dictionaries wit...
```python import json def extract_band_info(metadata): """ Extracts band information from the given satellite image metadata JSON object. Parameters: metadata (dict): A JSON object representing satellite image metadata. Returns: dict: A dictionary with asset keys and corresponding b...
Here's a Python function that extracts the band information from a given satellite image metadata JSON object according to the specifications you provided. Additionally, I've included test cases to ensure its correctness. ```python import json def extract_band_info(metadata): band_info = {} # Loop throug...
10,092
[ { "from": "human", "value": "\n\nWrite a Python function `extract_band_info` that takes a JSON object representing a satellite image metadata (following the structure of the given code snippet) and returns a dictionary containing the band information for each asset. The dictionary should have the asset keys...
Write a Python function `validate_package_json` that takes a JSON string representing a package configuration (similar to the given code snippet) and validates it against the following rules: 1. The JSON must contain the keys: `name`, `description`, `type`, `keywords`, `license`, `authors`, and `require`. 2. The `na...
```python import json def validate_package_json(json_string): """ Validates a JSON string representing a package configuration. Parameters: - json_string (str): A JSON string to validate. Returns: - bool: True if the JSON string is valid. Raises: - ValueError: If the JSON string is...
Here is a Python function that implements the required validation for a JSON string representing a package configuration: ```python import json def validate_package_json(json_str): try: # Parse the JSON string package_data = json.loads(json_str) except json.JSONDecodeError: raise Value...
10,093
[ { "from": "human", "value": "\n\nWrite a Python function `validate_package_json` that takes a JSON string representing a package configuration (similar to the given code snippet) and validates it against the following rules:\n\n1. The JSON must contain the keys: `name`, `description`, `type`, `keywords`, `l...
Write a Python function `update_package_versions` that takes a JSON string representing a `package.json` file (commonly used in Node.js and frontend projects) and a dictionary of package names with their new versions. The function should update the versions of the specified packages in both `dependencies` and `devDepe...
```python import json def update_package_versions(json_string: str, new_versions: dict) -> str: package_data = json.loads(json_string) for package_name, new_version in new_versions.items(): if package_name in package_data.get('dependencies', {}): package_data['dependencies'][package_n...
Here's a Python function that fulfills your requirements. It updates the versions of specified packages in a given `package.json` JSON string, both in `dependencies` and `devDependencies`. The function returns the updated JSON string in a properly formatted manner. ```python import json def update_package_versions(js...
10,094
[ { "from": "human", "value": "\nWrite a Python function `update_package_versions` that takes a JSON string representing a `package.json` file (commonly used in Node.js and frontend projects) and a dictionary of package names with their new versions. The function should update the versions of the specified pa...
Write a Python function `parse_test_details` that extracts and returns a dictionary with specific details from a JSON object representing a test case result. The JSON object has the same structure as the given code snippet. The function should extract the following details: - `uid`: The unique identifier of the test...
```python import json def parse_test_details(test_json: dict) -> dict: """ Extracts details from a test case JSON object. Parameters: - test_json (dict): A JSON object representing a test case result. Returns: - dict: A dictionary with extracted details including 'uid', 'name', 'status', 'd...
Certainly! Below is a Python function `parse_test_details` that extracts the specified details from a given JSON object representing a test case result. ```python def parse_test_details(test_json: dict) -> dict: """ Extracts details from a test case JSON object. Parameters: - test_json (dict): A JSON ...
10,095
[ { "from": "human", "value": "\n\nWrite a Python function `parse_test_details` that extracts and returns a dictionary with specific details from a JSON object representing a test case result. The JSON object has the same structure as the given code snippet.\n\nThe function should extract the following detail...
You are tasked with creating a function `translate_dict` that takes a dictionary of key-value pairs where the keys are in English and the values are their translations in Italian. The function should return a new dictionary where the keys remain the same, but the values are replaced with a tuple containing the origin...
```python def translate_dict(input_dict): """ Translates the values of a dictionary from Italian to uppercase English. :param input_dict: A dictionary with keys in English and values in Italian. :return: A new dictionary with the same keys and values as tuples of Italian and uppercase English. ...
You can create the `translate_dict` function as described, which will iterate through the original dictionary, check if the values are strings, and construct the new dictionary with the required tuple format. Below is the implementation: ```python def translate_dict(input_dict): output_dict = {} for key, ...
10,096
[ { "from": "human", "value": "\n\nYou are tasked with creating a function `translate_dict` that takes a dictionary of key-value pairs where the keys are in English and the values are their translations in Italian. The function should return a new dictionary where the keys remain the same, but the values are ...
Write a Python function `enhance_story_metadata` that takes a JSON string representing the metadata of a story and enhances it with additional information. The function should perform the following tasks: 1. Add a new field `average_words_per_chapter` which is the result of dividing `num_words` by `num_chapters`. 2. ...
```python import json def enhance_story_metadata(json_string): """ Enhances the story metadata with additional information. Parameters: - json_string (str): A JSON string representing the metadata of a story. Returns: - str: A JSON string with the enhanced metadata. """ # Par...
To enhance the story metadata as specified, we will define a function `enhance_story_metadata`. This function will take a JSON string, parse it, make the required modifications, and return the enhanced JSON string. Below is the implementation of this function: ```python import json def enhance_story_metadata(metadata...
10,097
[ { "from": "human", "value": "\nWrite a Python function `enhance_story_metadata` that takes a JSON string representing the metadata of a story and enhances it with additional information. The function should perform the following tasks:\n\n1. Add a new field `average_words_per_chapter` which is the result of...
Write a Python function `generate_block_model` that takes two arguments: `end_texture` and `side_texture`. The function should generate a JSON object that represents a Minecraft block model for a horizontally oriented column block, where `end_texture` is the texture for the top and bottom faces of the block, and `sid...
```python import json def generate_block_model(end_texture, side_texture): """ Generates a JSON string representing a Minecraft block model for a horizontally oriented column block. :param end_texture: The texture path for the top and bottom faces of the block. :param side_texture: The texture p...
Here is a Python function `generate_block_model` that constructs a JSON object based on the provided textures for a Minecraft block model, along with test cases to ensure its correctness. ```python import json def generate_block_model(end_texture, side_texture): block_model = { "parent": "minecraft:block/...
10,098
[ { "from": "human", "value": "\n\nWrite a Python function `generate_block_model` that takes two arguments: `end_texture` and `side_texture`. The function should generate a JSON object that represents a Minecraft block model for a horizontally oriented column block, where `end_texture` is the texture for the ...
You are tasked with creating a Python function that validates and processes company registration data provided in JSON format. The function should verify that the data includes all necessary fields, that the 'cedula_rnc' is a valid identifier consisting of only digits and exactly 9 characters long, and that the 'fech...
```python import json import re from datetime import datetime def validate_and_process_company_data(json_data): """ Validates and processes company registration data in JSON format. Parameters: - json_data (str): A JSON string containing company registration data. Returns: - dict: A...
To create a Python function that validates and processes the company registration data as specified, we can follow these steps: 1. **Check for necessary fields**: Ensure that the required fields are present in the JSON data. 2. **Validate `cedula_rnc`**: Ensure it is a string of exactly 9 digits. 3. **Validate `fecha_...
10,099
[ { "from": "human", "value": "\n\nYou are tasked with creating a Python function that validates and processes company registration data provided in JSON format. The function should verify that the data includes all necessary fields, that the 'cedula_rnc' is a valid identifier consisting of only digits and ex...