You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The behavior for the .to_json() method on YText, YArray, and YMap is not consistent with each other. YText returns a json serialized string. The other two return Python objects. I suggest these methods return JSON strings, and a separate .to_py() method be added to return the Python objects.
import y_py as Y
ydoc = Y.YDoc()
with ydoc.begin_transaction() as txn:
ytext = txn.get_text('text')
ytext.extend(txn, "foo")
yarray = txn.get_array('array')
yarray.append(txn, 'bar')
ymap = txn.get_map('map')
ymap.set(txn, 'key', 'value')
ytext.to_json(), yarray.to_json(), ymap.to_json()
>>> ('"foo"', ['bar'], {'key': 'value'})
import json
json.loads(ytext.to_json())
>>> 'foo'
json.loads(yarray.to_json())
>>> TypeError: the JSON object must be str, bytes or bytearray, not list
The text was updated successfully, but these errors were encountered:
The behavior for the
.to_json()
method onYText
,YArray
, andYMap
is not consistent with each other. YText returns a json serialized string. The other two return Python objects. I suggest these methods return JSON strings, and a separate.to_py()
method be added to return the Python objects.The text was updated successfully, but these errors were encountered: