Posts: 4,648
Threads: 1,495
Joined: Sep 2016
JSON (JavaScript Object Notation) is really just data in JavaScript syntax. you could insert it at the front of JavaScript source code with an assignment and it would have the data. so why not do the same thing in Python with PYON (PYthon Object Notation)?
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,648
Threads: 1,495
Joined: Sep 2016
the code i made supports a lot more than JSON does, so a converter to JSON would be very lossy. i don't know what PON does. i will have a look/see.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,648
Threads: 1,495
Joined: Sep 2016
Oct-30-2019, 01:10 AM
(This post was last modified: Oct-30-2019, 01:12 AM by Skaperen.)
the PON package seems to be well done except for one problem i noticed first. it encodes dictionaries using the form
dict( foo = 'bar' )
which does not support key values that are not strings with values that are valid identifiers.
that form can have security issues with untrusted data.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,648
Threads: 1,495
Joined: Sep 2016
if it coded a dictionary like
{'foo':'bar'}
then it should be able to make any key that is valid for a dictionary. maybe what PON does with a key as in
{4:'four'}
is decode
dict(4='four')
itself back the the original dictionary. but this is not valid syntax even if it is valid PON syntax. my code is trying to create valid Python source code.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,648
Threads: 1,495
Joined: Sep 2016
and PYON is similar to that except that it is based on Python itself and supports data types that Python supports which JavaScript/JSON does not, such as complex numbers, True, False, None, byte strings, and so on. it can be interpreted using exec() or in pieces by eval(). the code i have written also appends a slice expression after strings that shows the length of the string to make it easier for humans to read while still expressing the original value. while there is no module to handle PYON, yet, it would not be hard to create in Python. JavaScript would have more difficulty interpreting it, so PYON is not a replacement for JSON, except for very specific cases.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Posts: 4,648
Threads: 1,495
Joined: Sep 2016
PYON will be just as clear as JSON for a dictionary. it will be expressed as a mapping just as JSON does. that Python has a data structure to implement a dictionary is not only obscure to Python code, it will also be obscure in PYON.
Tradition is peer pressure from dead people
What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.