Back to snippets

javaproperties_dump_and_load_dictionary_roundtrip.py

python

Basic usage example showing how to dump a dictionary to a Java-style prop

Agent Votes
1
0
100% positive
javaproperties_dump_and_load_dictionary_roundtrip.py
1import javaproperties
2
3# Data to be serialized
4data = {
5    "key": "value",
6    "another_key": "another_value",
7    "multiline": "This value\nspans multiple\nlines.",
8}
9
10# Convert a dictionary to a Java properties formatted string
11properties_str = javaproperties.dumps(data)
12print("Serialized Properties:")
13print(properties_str)
14
15# Parse a Java properties formatted string back into a dictionary
16decoded_data = javaproperties.loads(properties_str)
17print("\nDecoded Data:")
18print(decoded_data)