ypy icon indicating copy to clipboard operation
ypy copied to clipboard

ydoc to json or some readable format

Open anujism opened this issue 2 years ago • 5 comments

Is it possible with ypy to convert the ydoc contents to some readable format?

anujism avatar Sep 16 '22 10:09 anujism

Hi @anujism, sorry for the delay. Are you trying to serialize the entire YDoc into something like a json representation?

Waidhoferj avatar Nov 07 '22 05:11 Waidhoferj

hi @Waidhoferj no issues. The problem is that I have a ydoc and I am trying to make it searchable. To do that I want to extract the ydoc to some readable format so I can put it into elastic search and make the contents searchable.

anujism avatar Nov 07 '22 05:11 anujism

We could probably make some iterator method over the root-level types. From there, you can always ask for their content one by one.

Horusiath avatar Nov 07 '22 05:11 Horusiath

Agreed, something like

doc = Y.YDoc(1)
message = doc.get_text("message")
with d.begin_transaction() as txn:
    message.extend("hello!")

# To get the contents of the doc
print(dict(doc.items()))

"""
{
"YText": { "message":  YText("hello!") }
}
"""

Waidhoferj avatar Nov 07 '22 06:11 Waidhoferj

yes, an iterator like that would be great!

anujism avatar Nov 07 '22 06:11 anujism