Json extension

a extension i created yesterday

purpose: bringing json to snap and adding more than the [scratchblocks] ( [json v] of list :: list ) [/scratchblocks]

https://snap.berkeley.edu/snap/snap.html#present:Username=mehone&ProjectName=json%20extension&editMode&noRun

This extension is very helpful!

The Snap! SPLIT BY JSON primitive doesn't distinguish JSON arrays from JSON objects with {name: value} pairs:


But the latter are arguably the main point of the JSON format, so your library should be aware of them. The JSON OF primitive interprets 2-D lists as objects, rather than as 2-D arrays:

You do have a json extension script pic (2) block that (like the SPLIT primitive) creates a length-2 list, but you don't index JSON strings by attribute name. That is, in addition to your json extension script pic (3) block, you should also have
json extension script pic (4)


or maybe

Note that it's an error to index an object by item position:

Similarly, things like REPLACE should be able to replace the value associated with a given name in the JSON string.

JavaScript, where JSON came from, has a primitive Object data type with key-value pairs. Snap! doesn't, instead using 2D arrays for that purpose. Thus, our ITEM block allows keyword indexing:


This semi-undiscoverable feature lets you type non-numeric text into ITEM's first input slot even though it's oval-shaped, not rectangular. We debated instead introducing dictionaries (the generic CS term for what JavaScript calls Objects) as a primitive data type separate from lists, but didn't, because from the very beginning we recognized that there are a bazillion aggregate data types that we might be called upon to support (hash tables, trees, etc.), but users can make all of them out of simple lists, provided lists of lists (recursively, to any depth) are supported. So arguably we should have implemented dictionaries as an abstract data type indicated by a type-tagged list:

and used that to represent JSON Objects. But it's really useful to be able to take any 2-D list, e.g. one loaded from a spreadsheet, and use one of the columns as keys. So we have this compromise.

How do I easily type text in a number input without having to use the join block or editing stuff or whatever?

The ITEM block just lets you do that. There's no nice way to do it on other blocks.

I know, but the only non-numeric characters I can write are "e" and "-".

"e" is for scientific notation (like 1e10 for 1010) and "-" is for negatives.

Yes, but I still want to write text into number inputs.

You'll be forced to use JOIN or a similar block then.

forgot to close your <sup>. :-)­

For some reason i put </small> instead of </sup>.

Ah. Makes sense.

sup small sub

i forgor about adding that

btw i didnt know about that, i tried making it similar to lists so when people know how lists work, they can easily use it

UPDATE:
added 'is json valid' block
changed the 'is json empty' block