Using .JSON file is it possible to construct block?

265 views
Skip to first unread message

Naresh Chaudhari

unread,
Mar 12, 2021, 8:03:40 AM3/12/21
to Blockly
Hi I have created some block related to object_block, array_block,  Inputkey_block, Inputvalue_block and object. 
Here is block:
 Capture.PNG
and my .json file contains following code:
"TestsuiteAnalytic": [
            {
                "Name": "Suite Result",
                "GraphType": "Bar",
                "GraphAttrib": [
                    {
                        "PrimaryCollection": "TestsuiteResult",
                        "xAxis": "RunCount",
                        "xAxisLabel": "Runs",
                        "yAxisLabel": "Test case count"
                    }
                ]
            },
            {
                "Name": "Suite Result solution stack",
                "GraphType": "Bar",
                "GraphAttrib": [
                    {
                        "PrimaryCollection": "TestsuiteResult",
                        "xAxis": "SolutionStack",
                        "xAxisLabel": "Solution Stack",
                        "yAxisLabel": "Test case count",
                    }
                ]
            }
        ]

===
Here, My query is: if I pass json code using some loop and condition and will be able to construct block in json specific format?
The output will be like:
Capture.PNG
If I will be able to generate the block dynamically based on JSON file it will save a lot of time. Thanks in advance... Any help will be appreciated... 



Beka Westberg

unread,
Mar 12, 2021, 3:05:22 PM3/12/21
to blo...@googlegroups.com
Hello,

It seems like what you're trying to do is convert from generated code back into blocks. Blockly doesn't itself provide any functionality for doing this, because it would be really hard to generalize :/ However! Since you're generating JSON, which has a pretty simple structure, it shouldn't be hard to create your own parser that takes in JSON and outputs block XML. Then you can deserialize the XML to get the blocks-version of your code :D

For information on XML I'd start by checking out the Blockly.Xml reference. It could also be helpful to manually create some blocks (as you've shown above) and then serialize them to see how the XML works.

I hope that helps! If you have any further questions please reply!
--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/1bc5725c-9490-43ef-8754-b51387fa0bc0n%40googlegroups.com.

Naresh Chaudhari

unread,
Apr 8, 2021, 10:21:40 AM4/8/21
to Blockly
Hi, I have solved it using pattern matching(Regular expression) and comparing the code char-by-char and it is generating the XML block based on input json code dynamically.. Validated testcase around 30+ and working perfectly. 
Reply all
Reply to author
Forward
0 new messages