Storing in JSON format

274 views
Skip to first unread message

Julian

unread,
Dec 27, 2021, 10:26:23 AM12/27/21
to Blockly
Hello,

I would like to store my workspace in JSON format instead of XML. I tried using these functions: https://developers.google.com/blockly/guides/get-started/web#importing_and_exporting_blocks

However, I am not able to get this to work ( I am using typescript and Blockly.serialization does not exist ).

When using JavaScript this code below always gives the same error.
var json = Blockly.serialization.workspaces.save(workspace);

I always receive this message: 
Schermafbeelding 2021-12-27 161855.png
What is workspaces? If I used the current workspace ( Blockly.getMainWorkspace() ) then I also get an error for that workspace being undefined. How can I use Blockly.serialisation for a workspace, or is there a different way to store the workspace with JSON ( maybe in a beta in this way Blockly.JSON.workspaceToDom(  Blockly.getMainWorkspace just like with Xml )?

Kind regards,

Julian

Beka Westberg

unread,
Dec 27, 2021, 10:41:15 AM12/27/21
to blo...@googlegroups.com
Hello Julian,

Looks like this is a problem with the transition to the new module system :/ It seems that `Blockly.serialization` is undefined, so the property `workspaces` cannot be read from it. I know there were problems with the generated typescript files this quarter (as stated in the release notes) but I'm not sure if this is related to that, or a different problem.

So your call to `Blockly.serialization.workspaces.save` is definitely correct! It's just something in Blockly that is broken :/

Best wishes,
--Beka

--
You received this message because you are subscribed to the Google Groups "Blockly" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blockly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/blockly/e9c9fe97-6e71-472b-bfa9-c797224855a2n%40googlegroups.com.

Julian

unread,
Dec 27, 2021, 11:36:05 AM12/27/21
to Blockly
Hello Beka,

Thanks for the reply, should report this problem somewhere ( which is also useful for me because I would like to use the call when it is fixed )?

Kind regards,

Julian de Bruin
Op maandag 27 december 2021 om 16:41:15 UTC+1 schreef bekawe...@gmail.com:

Beka Westberg

unread,
Dec 27, 2021, 12:06:03 PM12/27/21
to blo...@googlegroups.com
Yeah you can definitely report a bug on the github! However right now it is the Holiday Season in America, so it will probably be next week before you get a reply.

Best wishes!
--Beka

Mark Friedman

unread,
Dec 27, 2021, 3:28:58 PM12/27/21
to blo...@googlegroups.com
Julian,

  It might also be worth checking to see that you are using the latest published version of Blockly.  The Blockly.serialization modules were, I believe, added in the latest version, so the lack of them might indicate that you're using an older version.

-Mark


Julian

unread,
Dec 28, 2021, 7:04:59 AM12/28/21
to Blockly
Mark,

I have tried the beta version, but the when installing it the Blockly.d.ts file is different it is way smaller. It went from ~25000 lines to ~4000 lines, the majority of all types are gone. ( Examples of types which are gone Blockly.Block, Blockly.Generator, Blockly.FieldTextInput, Blockly.Workspace )
Thus I cannot compile my code, when replacing the new Blockly.d.ts file with the old one it does work, but I have 39 warnings ( I don't know where not in my code ) and this obviously is not the solution as every time I reinstall the node modules it will be gone.
Is there a ways to add the old types to the current Blockly.d.ts file from outside of the node modules? In addition am I doing something wrong or why are there almost no types in the beta version?

Kind regards,

Julian de Bruin

Op maandag 27 december 2021 om 21:28:58 UTC+1 schreef mark.f...@gmail.com:

Mark Friedman

unread,
Dec 28, 2021, 3:37:11 PM12/28/21
to blo...@googlegroups.com
Julian,

  When I referred to the "latest published version of Blockly", I meant the latest one published to npm (here), i.e. not the beta version.

-Mark


Julian

unread,
Jan 19, 2022, 12:34:08 PM1/19/22
to Blockly
Search: Changing node modules

Hello Mark,

I tried every published version containing Json serialisation, but none of them worked at that time, by now I think that has changed. 
However I temporarily solved the problem in the current time with Patch Package. By taking the old Blockly.d.ts file with all types and replacing the new one. 
Patch Package stores all changes in the node modules and this also works when deleting the nodemodules and reinstalling them. 

For more information on Patch Package: https://www.npmjs.com/package/patch-package 

I am sharing this for any future developers wanting to change the node modules, for example when working with beta versions where code is missing.

Kind regards,

Julian
Op dinsdag 28 december 2021 om 21:37:11 UTC+1 schreef mark.f...@gmail.com:

Mark Friedman

unread,
Jan 19, 2022, 3:58:41 PM1/19/22
to blo...@googlegroups.com
I'm glad that you found a solution which works for you, Julian!  That said, I am still unsure why it was needed.  The version of Blockly that was current at the time of your original message was version blockly-7.20211209.0 (which was released around Dec 9th) and I just verified that the blockly.d.ts in that version has 25596 lines in it (as do the subsequent two minor releases).

-Mark


Reply all
Reply to author
Forward
0 new messages