I would personally do something like this:

import json
import datetime

today = datetime.date.today()
tomorrow = today + datetime.timedelta(days = 1)

data = [{
    "date": str(tomorrow),
    "price": {
        "amount": 15100
    }
}]

print(json.dumps(data))

Of course, after this, you can do anything you want with json.dumps(data): in your case, send it in a request.

Answer from BrownieInMotion on Stack Overflow
🌐
Reddit
reddit.com › r/learnpython › json, strings, and f-strings
r/learnpython on Reddit: Json, strings, and f-strings
March 24, 2022 -

I'm stumped on how to fix this.

import json
import os

awx_base_url = "https://127.0.0.1”
inventory_name = "VCenter - POC”

build_number = 15
deploy_frontend = 'true'


to_deploy_dict = [

    {
        "name": " TEST”,
        "cmd": f"awx job_templates launch --inventory '{inventory_name}' --extra_vars '{{ build_number: {build_number}, deploy_frontend: {deploy_frontend} }}' 14",
     },
]

for item in to_deploy_dict:

    print("Executing: " + item["cmd"])
    if "workflow" in item["cmd"]:
          jobid = json.loads(os.popen(item["cmd"]).read())["id"]

The cli returns this error: {'variables_needed_to_start': ["Value True for 'deploy_frontend' expected to be one of ['true', 'false']."]}

Bypassing my script and using the cli directly, this command is successful.

 awx job_templates launch --inventory 'VCenter - POC' --extra_vars build_number: 15, deploy_frontend: 'true', 15 

What is getting lost in translation here?

🌐
Mimo
mimo.org › glossary › python › formatted-strings
Python Formatted Strings / f-string formatting Guide
f-strings also support JSON-friendly representations using repr, which ensures that objects are formatted in a readable string form. ... f-strings can include more than variables and values. They can include expressions, function calls, and even conditional logic: ... Python's so-called format mini-language provides advanced control over string formatting.
🌐
ReqBin
reqbin.com › code › python › trs5wpc0 › python-f-string-example
How to format string with f-string in Python?
July 27, 2023 - To print the variable value in ... be replaced by their values. In this Python F-String example, we are formatting a string using several variables....
🌐
Reddit
reddit.com › r/learnpython › nested f-string problem
r/learnpython on Reddit: Nested F-String Problem
July 3, 2022 -

Hi All,

I'm trying to dynamically change the body of this scrapy request (Offset specifically):

body = '{"xxxxQuery":{"query":"xxxxxxx","locations":[{"country":"gb","address":"xxxx","radius":{"unit":"mi","value":20}}]},"xxxxxxRequest":{"position":[1,2,3,4,5,6,7,8,9],"placement":{"channel":"WEB","location":"JxxxxxPage","property":"xxxxxxxxx","type":"xxxxxxxx","view":"SPLIT"}},"fingerprintId":"xxxxxxxxxxxxxx","offset":0,"xxxxxSize":9,"xxxxxxxx":[]}'

By using :

body = f{"xxxxQuery":{"query":"xxxxxxx","locations":[{"country":"gb","address":"xxxx","radius":{"unit":"mi","value":20}}]},"xxxxxxRequest":{"position":[1,2,3,4,5,6,7,8,9],"placement":{"channel":"WEB","location":"JxxxxxPage","property":"xxxxxxxxx","type":"xxxxxxxx","view":"SPLIT"}},"fingerprintId":"xxxxxxxxxxxxxx","offset":{value},"xxxxxSize":9,"xxxxxxxx":[]}

But I get an error saying the F-String is nested too deeply.

I've even tried to use the body as a dict instead of a string, change the key's value then re-convert back to string but the site returns that it is a bad request.

Any advice on how to get around it?

🌐
Real Python
realpython.com › python-f-strings
Python's F-String for String Interpolation and Formatting – Real Python
November 30, 2024 - In the upcoming sections, you’ll write a few more examples of formatting strings using the mini-language with f-strings. F-strings joined the party in Python 3.6 with PEP 498. Also called formatted string literals, f-strings are string literals that have an f before the opening quotation mark.
🌐
Marketcalls
marketcalls.in › home › mastering python f-string formatting: a trader’s guide
Mastering Python F-String Formatting: A Trader’s Guide
November 15, 2023 - json.loads is used to parse the JSON string into a Python object (in this case, a list of dictionaries). An f-string is used within a loop to format and print out each stock’s symbol and price.
Find elsewhere
🌐
Python documentation
docs.python.org › 3 › tutorial › inputoutput.html
7. Input and Output — Python 3.14.7 documentation
Numbers take a bit more effort, since the read() method only returns strings, which will have to be passed to a function like int(), which takes a string like '123' and returns its numeric value 123. When you want to save more complex data types like nested lists and dictionaries, parsing and serializing by hand becomes complicated. Rather than having users constantly writing and debugging code to save complicated data types to files, Python allows you to use the popular data interchange format called JSON (JavaScript Object Notation).
🌐
Databricks
community.databricks.com › t5 › get-started-discussions › using-f-strings-in-filenames-to-read-in-files-from-mounted › td-p › 36171
Using F Strings in filenames to read in files from... - Databricks Community - 36171
July 4, 2023 - Using F Strings in filenames to read in files from... ... Below are 2 versions of codes I tried and the failure messages. Does anyone have advice how to form this properly? ... for x in range(2,num_organization_page,1): file_str = f"dbfs:/mnt/dlsi2023/raw/ds_pet_finder_organization{x}.json", print(file_str) organizations_df = spark.read.option("multiline","true").json(f"{file_str}")
🌐
GeeksforGeeks
geeksforgeeks.org › formatted-string-literals-f-strings-python
f-strings in Python - GeeksforGeeks
June 19, 2024 - To create an f-string, prefix the ... string literals for formatting. In the below example, we have used the f-string inside a print() method to print a string....
🌐
freeCodeCamp
freecodecamp.org › news › python-f-strings-tutorial-how-to-use-f-strings-for-string-formatting
Python f-String Tutorial – String Formatting in Python Explained with Code Examples
September 14, 2021 - Strings in Python are usually enclosed within double quotes ("" ) or single quotes (''). To create f-strings, you only need to add an f or an F before the opening quotes of your string. For example, "This" is a string whereas f"This" is an f-String.
🌐
GeeksforGeeks
geeksforgeeks.org › json-formatting-python
JSON Formatting in Python - GeeksforGeeks
August 23, 2023 - The JSON module provides the following two methods to encode Python objects into JSON format. We will be using dump(), dumps(), and JSON.Encoder class. The json.dump() method is used to write Python serialized objects as JSON formatted data into a file. The JSON. dumps() method encodes any Python object into JSON formatted String.
🌐
DataCamp
datacamp.com › tutorial › python-f-string
Python f-string: A Complete Guide | DataCamp
December 3, 2024 - In this tutorial, you'll learn all about Python Strings: slicing and striding, manipulating and formatting them with the Formatter class, f-strings, templates and more! ... Learn about Python string interpolation, its purpose, and when to use it. Includes practical examples and best practices.
🌐
Javatpoint
javatpoint.com › f-string-in-python
F String in Python - Javatpoint
F String in Python - F String in Python with python, tutorial, tkinter, button, overview, entry, checkbutton, canvas, frame, environment set-up, first python program, operators, etc.
🌐
Boot.dev
boot.dev › blog › python › python f-strings: syntax, examples, and formatting
Python F-Strings: Syntax, Examples, and Formatting | Boot.dev
August 24, 2026 - An f-string, short for formatted string literal, creates a string while inserting dynamic values into it. Python added the syntax in version 3.6 via PEP 498. num_bananas = 10 bananas = f"You have {num_bananas} bananas" print(bananas) # You have ...
🌐
DZone
dzone.com › coding › languages › python f-strings
Python F-Strings - DZone
August 22, 2023 - In Python, F-strings are a way to embed expressions inside string literals, using a simple and concise syntax. F-strings start with the letter f and are followed by a string literal that may contain expressions that are evaluated at runtime and replaced with their values. These expressions are enclosed in curly braces: {}. For example, the following code prints the value of the variable name inside a string:
🌐
W3Schools
w3schools.com › python › python_json.asp
Python JSON
Convert a Python object containing all the legal data types: import json x = { "name": "John", "age": 30, "married": True, "divorced": False, "children": ("Ann","Billy"), "pets": None, "cars": [ {"model": "BMW 230", "mpg": 27.5}, {"model": "Ford Edge", "mpg": 24.1} ] } print(json.dumps(x)) Try it Yourself » · The example above prints a JSON string, but it is not very easy to read, with no indentations and line breaks.