Hopscotch project JSON reader

hopscotch-json

#1

Hey Hops just completely for fun, i just made a small program to get the JSON from a project url and save it into a file. it's a little pointless at the moment :laughing: but was very interesting trying to work out how to try and do it, along with looking things up along the way :slight_smile:

I would love to share the code, just at the moment it is very messy and makes no sense :laughing: but if Hops are interested, would very very much love to try explain :blush:

Note:

(this is just a link so you can see the code if you would like, just a reminder to keep communication here to forum :relaxed: and I don't have extra personal info there or anything that isn't allowed here; GitHub is just a site used to share code :blush:

But THT if you would like me to remove this then I can do that, no problem; it just means I will have to copy paste code manually and it won't automatically update if I make changes, but that will be okay :slight_smile: )


Please feel very free to ask about anything! I can imagine a first question might be:

What is JSON? (JavaScript Object Notation)
It is just a format for storing data in general, not a great first explanation but I can elaborate. There are mentions around the forum too about it if you can't wait for me :stuck_out_tongue: (searching 'Hopscotch json' brings up most stuff)

Edit: you can see what it looks like for now here:

Can I try running the code?

Most certainly! If you are asking this question, of course I can show you :) and looks like I can go with making a tutorial now :P for the time being:
  • you can go to the link and copy and paste the code into a text editor (if you are not sure about this, IDLE is where you can start)

  • save it as a Python file somewhere (just add .py to the end of the file name)

  • in the folder where you saved it, make another folder and call it project_data

  • open the Python file again and go to the last line, where it says read_url('https://c.gethopscotch.com/p/ykcmajup8.html') but replace that link with any project link you like (you may have to add .html at the end there after you paste the project link in)
    (these are not very accessible instructions so I would like to update if anyone wants to try)

  • run the project (if you are using IDLE, you can press F5)

  • after a little wait, you can go to the project_data folder and a .json file will appear. this is the project JSON file. If you haven't seen it before, hopefully later on maybe I can try point out a few things :slight_smile:

  • Oh dear I just remembered you might have to download some python libraries which is a bit extra, I will have to address that later. This is just an initial thing :relaxed: so sorry if this doesn't work :(


I would like to thank all previous Hops and discussions on forum referring to the JSON files for projects :slight_smile: it encouraged me to explore! I will update this if anyone is interested :stuck_out_tongue:

P.S. If this looks a little bit like 'ahhhh!' please don't feel like that(!) one of the reasons of me sharing this is so that you can get to see and have a chance to try understand a few more things too! And plus I am sharing this very quickly at the moment and not explaining much at all :joy: hence I've just made it even more confusing >_<

Also this is basically my first time peeking around, so if this isn't a good idea (e.g. for any security purposes or anything, I did hear something about that), Hopscotch Team, please let me know :smile:


Hopscotch web IDE/code viewer docฯ…mentation
Project JSON modification โ€” Topic
Project JSON modification โ€” Topic
#2

What is json


#3

Amazing job! The code is very neat, too. So, you have now made a project that can read JSON's, I think the natural next step - one that can edit them :slight_smile:


#4

Wow! That is very neat and organized! I can see everything and where everything is! Great joB, (It sounds so werid to say that cause you are much older than me... I shouldn't have said that) :smiley:


#5

Wow, this is amazing! I love how organized the code is, great job! :D


#6

This is amazing! Great job @t1_hopscotch


#7

I'm going to try this out later. This looks sweet. Good job @t1_hopscotch!


#8

Whoops, should have added that it stands for JavaScript Object Notation, but that itself doesn't explain much :joy: I will add that in though to clarify!


Wow thanks BuildASnowman :relaxed: You are one of the people I would like to thank! โ€” I learnt from peeking around on the forum seeing what you've talked about regarding Hopscotch project JSONs :slight_smile:

Hehe, I actually did have more plans that I didn't mention โ€” I was hoping/dreaming (dreaming, more like) to make something so that you could view the code blocks more easily from a non iOS device (for example, if you're on a computer, when someone links a project, you might just want to see the blocks which would be enough to help with a problem/question or just see how an aspect works for example, but you can't do that at the moment).

I actually didn't think much about an editor (I thought it might be beyond me just at this point :slight_smile:) โ€” I saw @Rawrbear and @K1ish were working on one using GameMaker, but now I think about it, that would be pretty... fun... :thinking::open_mouth::yum: I'd need to be more familiar with how the blocks/code is arranged in the JSON file, but I think I can sort of see how to try edit the data using Python.. :thinking:

(I recently got to be part of working on a website that uses Python for a server, so having it hosted as a website is a potential possibility.. :open_mouth: but like I just said, these are just little dreams at the moment :stuck_out_tongue: but would be very, very fun to try and do :relaxed:)


Ooh thank you Sweetlina; I thought it would be pretty messy and confusing :joy: I will still try to clear it up though I think :slight_smile: And also, I think it's lovely that you're giving encouragement :blush: that's awesome, no matter how old anyone is :relaxed: (also I don't think ive really mentioned much about my age anyway actually :stuck_out_tongue:)

Thank you @Dude73 and @William04GamerA too :relaxed:


Ooh I can go update the instructions :stuck_out_tongue: (I shouldn't wait for a good reason, but this is a great one!) And also thanks to you too, @MR.GAM3R โ€” I learnt from seeing you talking about project JSONs around the forum too :blush:


I would like to add that like 90% of the code there was searched up basically; really! :joy: โ€” it is awesome seeing that you can indeed learn as you go!


#9

That's really cool X3


#10

That's very clever. Great work.


#11

I will just jot down a few things here :slight_smile:

You can edit this too, you know!

Ideas/investigations/possible todos :clipboard::

  • :white_check_mark: can save project to a file

  • document more on Hopscotch project JSONs so more Hops can see :relaxed:

  • possibly, see how going in another language might go

(Dreams) :thought_balloon::

  • render blocks in JSON files for viewing??
  • edit JSON files??
  • Discourse plugin??? so we can view directly on forum (very big dream)

Wonderings :thinking::

  • Does the order of keys in dictionaries matter for Hopscotch reading a JSON file? (In Python, the key order for dictionaries is different every time you start it)
  • What does the JSON for code look like if I put more blocks in a project? (e.g. have Ifs and Repeats inside each other, and Draw Trail and so on)
  • general idea of structure of JSON file

'Purposes':

(this doesn't really have a purpose โ€” main is just for fun :stuck_out_tongue:)

  • Just for fun!
  • So Hops can see more with project JSONs
  • Viewing code for projects more conveniently โ€”
    e.g. if someone has a question about why some code isn't working as expected, or if you just want to See Code for a project while viewing in a browser and you don't have an iOS device with you

"Can I get involved...?"

Yes!!

  • @Rawrbear has ideas for a Hopscotch IDE (integrated development environment) where you can make and edit Hopscotch projects :open_mouth:
  • Organising all these posts I've made :joy:
    (e.g. group together similar/related things, having a list where everything is, updating todo lists maybe โ€” these are not what you have to do; I enjoy doing these too and I can do these myself, it is just if you like doing that sort of thing as well, then go for it :stuck_out_tongue:)

  • Styling for the blocks (when it comes to displaying the actual blocks, e.g. making the text for all the Movement blocks red etc. Will probably involve HTML & CSS, you can learn about those! here: https://www.w3schools.com

  • And of course if you want to try some of the programming, you are most welcome to do so!

  • And anything that you can dream of. This itself is a dream :joy:

Resources:

https://www.w3schools.com/js/js_json_intro.asp


Hopscotch web IDE/code viewer docฯ…mentation
#12

Jotting down a few other things... This is more informational.

Again, please feel very free to edit.

How the program works:

A general text description:

get the html from a project url
look for <div> tag that has a `data` attribute
get the value of that `data` attribute (as a string)
convert to an object (or anything that you can manipulate)
save the object to a JSON file

How to view the project JSON in your web browser (!)

  1. Go to project link and right click over the player:

  2. Click Inspect Element (how to peek behind the scenes of any website, or, in other words, 'how 2 become L33T H4x0r/a mad hacker' like in this PyCon (Python conference) talk)

    I'm using Safari, but this functionality is common to pretty much most browsers at least. In Safari, I navigated to Elements to see the HTML (hypertext markup language โ€” is code used to make websites and uses <tags> to wrap around different things)

    You'll find the JSON in the data= part of a <div> somewhere, and you'll see it in a reaally long line:

You can copy and paste that somewhere and try to separate it manually, or the project files that are saved using the program I put above will have that automatically done too. I think some people have text editors that can also collapse things automatically for them, which is very handy (but I don't have one that does. I have one that colours text so I can see things a little clearer though, it is called Atom.)

What does the project JSON contain???

I am still exploring this too :slight_smile: Some things you might see:

  • 'Hey, I can see some block names!' Yep there are the names of the blocks, this is the data for storing the blocks in projects I believe :slight_smile: Let's take a look at some (or one or two).


    [I may have to leave this til later, but you can see this is an example for Grow by 10% :slight_smile: for now]

  • Anything that is a generated ID will often be a really long sequence of characters. Generally, IDs need to be unique and the longer a string is, the more options you have for naming it.



    (For example, if you have a one-letter long name, there are 26 letters in the English alphabet that you can choose for it. But if you extend it to 2 characters, now you have 26*26 = 676 options for names. You can imagine the more characters it becomes, the more options you'll have. If you have a system that has heaps and heaps of objects, you'll need pretty unique names.)

    Also I think there are probably security reasons too for IDs seeming long and a little random. And there'll be other reasons too. I'm mentioning this mainly for if you happen to be looking at them and going like 'why is this so long??' which would be totally okay by the way :stuck_out_tongue:

I heard we can edit the JSON. What happens if I edit the JSON?

There is a way to put JSON projects back into your Drafts (and get them from your Drafts) using iTunes and connecting your device to a computer. If the editing is valid JSON for a Hopscotch project, the changes will be made in the project too. There are Hops who are more familiar with this (plus the Hopscotch Team too of course :)

I'm not exactly sure how it works in Hopscotch but I just know JSON is a way of storing data generally. This is from a veery limited understanding and my initial aim is just to make this more accessible :relaxed: so please feel very free to correct.

So I'm guessing: the JSON isn't exactly the project itself, it is a way of storing what is in the project. You store that the user who made the project is t1 (for example) and that these particular blocks are in the project (e.g. Draw Trail, Move Forward 300 etc.) And when the editor opens a project, it looks at these notes (what blocks are in it, in what order, what objects you said were in there, and who made it etc) and then knows what to show or display.

if you start copying and pasting the JSON section for a Grow block or something, and repeat doing that in a row, logically I'm guessing you'll end up with a whole bunch of Grow By blocks in your project rule, right? Well, you know what, let's go find that out... :open_mouth: coz we can do that :stuck_out_tongue: (might have to try later though coz I will have to head off for now :stuck_out_tongue_closed_eyes:)

And with the JSON 'not being the actual project itself', peeking around, I can see that the filename for a project ends in .hopscotch, so you can sort of see the JSON specifies more of the contents of a project โ€”the blocks and rules inside it, its objects, its creator etc.


Hopscotch web IDE/code viewer docฯ…mentation
#13

Is this code open source? I'd like to figure out a way to use this in our project, if possible. ^^


#14

Hi Rawrbear! Yes! :smiley: it is the first link at the very top of the topic :relaxed: that is awesome, (dream would be to work with others) Feel very free to ask about anything :blush:


#15

Is Python a web language (meaning you can integrate it into websites)? Don't know much about it, lol.


Changing the default settings- Idea for Hopscotch
#16

That's so confusing and cool XD


#17

Ahh, thank you so much! I'll try learning C++ as fast as possible to get the application out sooner (if school isn't in the way too much). :smiley:


#18

Yeah, you can import Python plugins into a website! You can also make/run Python PC applications and plugins with it if you install the language. ^^


#19

Oh man - this is exactly what I hoped for when I published my hack. JSON's are the key to hopscotch, and you are now the gatekeeper :stuck_out_tongue:

I made a programming language that translates to Hopscotch jsons before, to be able to make projects on my computer. I know quite a bit about the structure of these files - if you ever have a question, don't hesitate to ask :smiley:


#20

Yeah you can use Python for a number of things (it is referred to as a 'general purpose' programming language) :relaxed:

Wow are you using C++ for the JSON editor that you were working on? :open_mouth: haha there's no rush or anything :relaxed::blush: I see you're pretty keen about it though! and you must have quite a few things on your plate already too :slight_smile:

Wow that's awesome to hear :relaxed: and wow... :open_mouth:

That is really cool!! A programming language, did you say? :open_mouth: that is epic; how does it work? And that's lovely; thank you so much, I think I'll have quite a few questions already actually :joy: I think for the moment they're things that I can investigate myself first for now (and will probably get a better idea if I look through closely first)

Oh, I have some of my wonderings in one of the posts above, actually :slight_smile: I think I just need to get a general idea by peeking around more first.