To go from a Python object to an Zish string use zish.dumps
. To go from an
Zish string to a Python object use zish.loads
. Eg.
>>> from zish import loads, dumps >>> from datetime import datetime, timezone >>> from decimal import Decimal >>> >>> # Take a Python object >>> book = { ... 'title': 'A Hero of Our Time', ... 'read_date': datetime(2017, 7, 16, 14, 5, tzinfo=timezone.utc), ... 'would_recommend': True, ... 'description': None, ... 'number_of_novellas': 5, ... 'price': Decimal('7.99'), ... 'weight': 6.88, ... 'key': b'kshhgrl', ... 'tags': ['russian', 'novel', '19th century']} >>> >>> # Output it as an Zish string >>> zish_str = dumps(book) >>> print(zish_str) { "description": null, "key": 'a3NoaGdybA==', "number_of_novellas": 5, "price": 7.99, "read_date": 2017-07-16T14:05:00Z, "tags": [ "russian", "novel", "19th century", ], "title": "A Hero of Our Time", "weight": 6.88, "would_recommend": true, } >>> >>> # Load the Zish string, to give us back the Python object >>> reloaded_book = loads(zish_str) >>> >>> # Print the title >>> print(reloaded_book['title']) A Hero of Our Time
Python Type | Zish Type |
---|---|
bool |
bool |
int |
integer |
str |
string |
datetime.datetime |
timestamp |
dict |
map |
decimal.Decimal |
decimal |
float |
decimal |
bytearray, bytes |
bytes |
list, tuple |
list |
-
Change to the
zish
directory:cd zish
-
Create a virtual environment:
virtualenv --python=python3 venv
-
Activate the virtual environment:
source venv/bin/activate
-
Install tox:
pip install tox
-
Run tox:
tox
-
Use 1-based line and character numbers, rather than zero-based.
-
Arrow time library upgraded.
-
Line and character numbers now available in errors
-
Change formatting for map and list in dumps. The trailing } and ] are now on a line down and at the original index.
-
Remove '//' as a comment, following change in spec.
-
Allow 'e' and 'E' in the exponent of a decimal, following change in spec.
-
Better error message when the end of the document is reached without a map being closed.
-
Fix bug where an integer after a value (and before a ',' or '}') in a map doesn’t give a good error.
-
A map key can now be of any type.
-
The 'set' type has been removed from Zish.
-
Zish now recognizes the full set of Unicode EOL sequences.
-
The 'float' type has been removed from Zish.
-
Fixed bug when sorting map with keys of more than one type.
-
Give a better error if the end of the document is reached before a map is completed.
-
Give an error if there are multiple top-level values, rather than silently truncating.
-
Tighten up parsing of container types.
-
Make sure floats are formatted without an uppercase E.
-
Fixed map parsing bug where an error wasn’t reported properly if it was expecting a
:
but got an integer.
-
Fix bug where
int
was being parsed asDecimal
. -
Make bytes type return a
bytes
rather than abytearray
.
-
Fixed bug where interpreter couldn’t find the
zish.antlr
package in eggs. -
Removed a few superfluous escape sequences.