Python Forum

Full Version: JSON vs PYON
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
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)?
There is a PON module in pypi... I don't know if converters exist from one format to another.
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.
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.
Skaperen Wrote:that form can have security issues with untrusted data.
This depends only on how it is parsed and interpreted. There is no more information in dict(foo='bar') than in {'foo':'bar'}. It is not intrinsically more dangerous.
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.
(Oct-29-2019, 04:03 AM)Skaperen Wrote: [ -> ]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)?

The full-form of JSON is JavaScript Object Notation. It means that a script (executable) file which is made of text in a programming language, is used to store and transfer the data. Python supports JSON through a built-in package called JSON. To use this feature, we import the JSON package in Python script. The text in JSON is done through quoted-string which contains a value in key-value mapping within { }. It is similar to the dictionary in Python. JSON shows an API similar to users of Standard Library marshal and pickle modules and Python natively supports JSON features.
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.
JSON is a data format (a string), Python dictionary is a data structure (in-memory object). If you need to exchange data between different (perhaps even non-Python) processes then you could use JSON format to serialize your Python dictionary.
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.
Pages: 1 2