SmallBASIC icon indicating copy to clipboard operation
SmallBASIC copied to clipboard

JSON support?

Open shlwapi opened this issue 3 years ago • 5 comments

Something like the Python API?

https://www.w3schools.com/python/python_json.asp

shlwapi avatar Aug 29 '22 12:08 shlwapi

Yes JSON is supported.

Here's an example: https://github.com/smallbasic/smallbasic.github.io/blob/58e9d03ec5260ff9c29a6067f50988e72c3cabb1/samples/node/1266.bas

chrisws avatar Aug 30 '22 02:08 chrisws

Yes JSON is supported.

Here's an example: https://github.com/smallbasic/smallbasic.github.io/blob/58e9d03ec5260ff9c29a6067f50988e72c3cabb1/samples/node/1266.bas

This is about reading JSON. What about writting JSON? I want to write formatted JSON like json.dump() of Python.

@chrisws

shlwapi avatar Aug 30 '22 20:08 shlwapi

No answers means not available man. JSON is always related to Object. This language has no Objects (nor structures), so the best it could map JSON is to an Array (Array of this language is in fact a List). There will be no intuitive way to construct an "JSON Array".

ghost avatar Sep 02 '22 01:09 ghost

Sorry for the late reply. Actually you can write JSON by passing a map variable to STR(), like this:

foo={}
foo.dog = "jessie"
foo.hello = "you"
print str(foo)

prints: {"dog":"jessie","hello":"you"}

chrisws avatar Sep 02 '22 05:09 chrisws

Also: another example worth examining:

https://github.com/smallbasic/SmallBASIC/blob/master/samples/distro-examples/games/2048.bas

It would be possible to write an extension module with more extensive JSON support.

chrisws avatar Sep 02 '22 05:09 chrisws