Giter Club home page Giter Club logo

jsonlib's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

jsonlib's Issues

Add pretty printing string representation

@LFSaw suggested that having a pretty printer for the object to string method would be nice and I agree - I used vscode multiple times to make the JSON look more convenient during debugging, and after all, JSON is a human readable format and its reference implementation in JavaScript also offers this feature natively.

Examples

I looked up the JS and the Python implementation and they both offer adding an indentation in their "transform object to string" method

JavaScript: JSON.stringify

space
A string or number that's used to insert white space (including indentation, line break characters, etc.) into the output JSON string for readability purposes.

If this is a number, it indicates the number of space characters to be used as indentation, clamped to 10 (that is, any number greater than 10 is treated as if it were 10). Values less than 1 indicate that no space should be used.

If this is a string, the string (or the first 10 characters of the string, if it's longer than that) is inserted before every nested object or array.

If space is anything other than a string or number (can be either a primitive or a wrapper object) — for example, is null or not provided — no white space is used.

Python: json.dumps

indent
If indent is a non-negative integer or string, then JSON array elements and object members will be pretty-printed with that indent level. An indent level of 0, negative, or "" will only insert newlines. None (the default) selects the most compact representation. Using a positive integer indent indents that many spaces per level. If indent is a string (such as "\t"), that string is used to indent each level.

Implementation: https://github.com/python/cpython/blob/ffb41eaaf4b04f7f52ee095253fcc1c5ba62ca28/Lib/json/encoder.py#L288-L295

I don' t really understand the length of 10 restriction in JS, so maybe just copy the python behavior as it seems to cover pretty much anything?

Add object methods

Although I prefer the more OO based approach we should also implement add methods to existing classes which is the more common thing to do in SC.
Within the added methods we can simply use the JSONlib class.

+ Dictionary {
    asJson {
        ^JSONlib.encode(this);
    }
}

The problem is the parsing as there already exists a parseJson method which is not really what you want, so a proper naming should be discussed.

support for json5?

Thanks again for this wonderful add-on, I use it all the time :)
I was wondering:

There's a (simple) extension to json called json5 that especially includes comments and is targeted towards human readablity. Might be worth looking into to support?

Example from the website:

{
  // comments
  unquoted: 'and you can quote me on that',
  singleQuotes: 'I can use "double quotes" here',
  lineBreaks: "Look, Mom! \
No \\n's!",
  hexadecimal: 0xdecaf,
  leadingDecimalPoint: .8675309, andTrailing: 8675309.,
  positiveSign: +1,
  trailingComma: 'in objects', andIn: ['arrays',],
  "backwardsCompatible": "with JSON",
}

A more real-world example is this config file from the Chromium/Blink project.

Add custom en-/decoders

I think it would be neat to allow for custom parsing functions - this would allow e.g. to dump function source code in a JSON file which then could be encoded into a function again during parsing.
As this is not part of the official JSON implementation we should not implement it in this lib, but we should allow people to use hooks for this, see e.g. how the python implementation of JSON solves this https://docs.python.org/3/library/json.html#json.JSONEncoder as an inspiration

clean repository?

Do you wan to clean the history of the repository or open it as it is? It was developed in closed form, so this needs to be ckecked.

Create a logo

Add a crossover logo b/c the JSON logo is simillar to the SC IDE one.
Optional.

Write documentation

Maybe as a last step before release so the interface does not change.

To cover:

  • Dictionary vs Event
  • Cover deviations from the standard
    • #18
    • The null/nil issue (see #5 )
  • Cover problems of implicit casting ({"foo": "42.0"} will become (foo: 42.0) instead of a string)

Bonus:

grafik

Add tests

Maybe there is a resource for hard-to-parse JSONs with lots of edge cases concerning

  • escaping in string (", and \)
  • number parsing like .5 or 10e4
  • invalid escaping

See json.org for the implementation details

Replace JSONlibNull with Nil

TIL

// does not work
(\a: nil);
-> (  )
// does work
(\a: Nil);
-> ( 'a': class Nil )

So its probably best to use the build in data type

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.