import streamlit as st
import jiter
# based on https://github.com/pydantic/jiter/tree/main/crates/jiter-python
json_data = b'{"name": "John", "age": 30}'
parsed_data = jiter.from_json(json_data)
st.write(parsed_data) # Output: {'name': 'John', 'age': 30}
partial_json = b'{"name": "John", "age": 30, "city": "New Yor'
# Raise error on incomplete JSON
try:
jiter.from_json(partial_json, partial_mode=False)
except ValueError as e:
print(f"Error: {e}")
# Parse incomplete JSON, discarding incomplete last field
result = jiter.from_json(partial_json, partial_mode=True)
st.write(result) # Output: {'name': 'John', 'age': 30}
# Parse incomplete JSON, including incomplete last field
result = jiter.from_json(partial_json, partial_mode='trailing-strings')
st.write(result) # Output: {'name': 'John', 'age': 30, 'city': 'New Yor'}