capturegraph.data.typed_json
#
PType JSON Serialization#
Extensible JSON serialization for CaptureGraph PTypes (primitive typed values).
PTypes are the iOS-compatible JSON formats used for data exchange between the Python library and the iOS app. Each PType wraps a value with type metadata, enabling type-safe serialization and deserialization.
Supported PTypes
- PBool: {"bool": true/false}
- PNumber: {"number": 42, "is_time_interval": false}
- PString: {"string": "hello"}
- PTime: {"time_since_1970": 1737000000.0}
- PLocation: {"latitude": 42.0, "longitude": -76.0, "altitude": 100.0}
- PWeather: WeatherKit condition dict
Example
import capturegraph.data as cg
from datetime import datetime
# Encode Python objects to PType JSON
cg.typed_json.encode(datetime.now()) # {"time_since_1970": ...}
cg.typed_json.encode(42) # {"number": 42, "is_time_interval": false}
# Decode PType JSON to Python objects
cg.typed_json.decode({"time_since_1970": 1737000000}) # datetime
# Full serialization to/from JSON strings
json_str = cg.typed_json.dumps({"time": datetime.now()})
data = cg.typed_json.loads(json_str)
The dumps function also handles numpy/pandas types via recursive_cast,
converting them to native Python types before PType encoding.
Modules:
| Name | Description |
|---|---|
handlers |
|
type_handler |
|
typed_json |
|