Coder Social home page Coder Social logo

lightjson's People

Contributors

bjornhellander avatar marcoslopezc avatar saiedkia avatar sharwell avatar tstavropoulos avatar vsilvar avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

lightjson's Issues

Complex JSON format

Can you implement the following complex JSON formats:

{
    "name": "Materials",
    "version": "1.0",
    "scene": {
        "SceneUnit": 8215,
        "YIsUp": 0
    },
    "materials": {
        "0": {
            "version": 2,
            "userassets": [
                "0"
            ],
            "materials": {
                "0": {
                    "tag": "",
                    "definition": "XXXX",
                    "properties": {
                        "integers": {
                            "mode": 4
                        },
                        "booleans": {
                            "generic_bump_is_normal": false,
                            "generic_is_metal": false,
                            "generic_backface_cull": false
                        },
                        "scalars": {
                            "generic_reflectivity_at_0deg": {
                                "values": [
                                    0.2
                                ]
                            },
                            "generic_glossiness": {
                                "values": [
                                    0.0
                                ]
                            }
                        },
                        "colors": {
                            "generic_diffuse": {
                                "values": [
                                    {
                                        "r": 1.0,
                                        "g": 1.0,
                                        "b": 1.0
                                    }
                                ]
                            },
                            "generic_specular": {
                                "values": [
                                    {
                                        "r": 0.2,
                                        "g": 0.2,
                                        "b": 0.2
                                    }
                                ]
                            }
                        }
                    },
                    "transparent": false,
                    "textures": {
                        "generic_diffuse": {
                            "connections": [
                                "1_generic_diffuse"
                            ]
                        }
                    }
                },
                "1_generic_diffuse": {
                    "tag": "",
                    "definition": "UnifiedBitmap",
                    "properties": {
                        "uris": {
                            "unifiedbitmap_Bitmap": {
                                "values": [
                                    "xxxxx"
                                ]
                            }
                        },
                        "booleans": {
                            "unifiedbitmap_Invert": false,
                            "texture_URepeat": true,
                            "texture_VRepeat": true
                        },
                        "scalars": {
                            "texture_UScale": {
                                "units": "",
                                "values": [
                                    0.0625
                                ]
                            },
                            "texture_VScale": {
                                "units": "",
                                "values": [
                                    0.0625
                                ]
                            },
                            "texture_UOffset": {
                                "units": "",
                                "values": [
                                    0.0
                                ]
                            },
                            "texture_VOffset": {
                                "units": "",
                                "values": [
                                    0.0
                                ]
                            },
                            "texture_WAngle": {
                                "units": "",
                                "values": [
                                    0.0
                                ]
                            }
                        },
                        "integers": {
                            "texture_MapChannel": 1
                        }
                    }
                }
            }
        },
        "1": {
            "version": 2,
            "userassets": [
                "0"
            ],
            "materials": {
                "0": {
                    "tag": "",
                    "definition": "SimplePhong",
                    "properties": {
                        "integers": {
                            "mode": 4
                        },
                        "booleans": {
                            "generic_bump_is_normal": false,
                            "generic_is_metal": false,
                            "generic_backface_cull": false
                        },
                        "scalars": {
                            "generic_glossiness": {
                                "values": [
                                    64.0
                                ]
                            }
                        },
                        "colors": {
                            "generic_diffuse": {
                                "values": [
                                    {
                                        "r": 0.49803921568627452,
                                        "g": 0.49803921568627452,
                                        "b": 0.49803921568627452
                                    }
                                ]
                            }
                        }
                    },
                    "transparent": false,
                    "textures": {}
                }
            }
        }
    }
}

Suggestion: Release source code nuget package

Currently, due to roslyn limitations, it's rather cumbersome to use Json libraries in source generators.
One approach, taken by https://github.com/DotNetAnalyzers/StyleCopAnalyzers was to copy over the code, and maintain it.
But it would be extremely useful to, instead, either have the source code embedded in the current package, or release a dedicated source code package.

As an example, scriban, already does that: https://github.com/scriban/scriban#source-embedding

I think if that was implemented, it would make it a very nice package to use in source generators.

Add method `AddIfNotNull`.

Add the method AddIfNotNull to JsonObject and JsonValue. This method will add an item to its collection if the value is not null.

Error position reported by TextScanner.Assert is off by one

Code:

JsonValue.Parse("trUe");

Expected result: Error at line 0, column 2

Actual result: Error at line 0, column 3

Cause: TextScanner.Assert calls TextScanner.Read before validating the character, which causes the position to move forward by one. The current position needs to be stored in a local variable before calling Read so it can be used for positioning in the event of an error.

πŸ”— This was originally found in DotNetAnalyzers/StyleCopAnalyzers#2406.

Request to decrease target framework

This project is currently targeting .NET Standard 2.1, which makes it unusable in any application targeting .NET Framework. I request a decrease in the target framework to .NET Standard 2.0 instead, to make it usable in more applications.

Write wiki page

Write a wiki page describing how to integrate and use LightJson.

Support read Hex

JsonReader.cs

    private void ReadHexNum(StringBuilder builder)
    {
        while (this.scanner.CanRead && char.IsLetterOrDigit(this.scanner.Peek()))
        {
            builder.Append(this.scanner.Read());
        }
    }

private JsonValue ReadNumber()
{
....
if (this.scanner.CanRead && char.ToLowerInvariant(this.scanner.Peek()) == 'e')
{
...
}

if (this.scanner.CanRead && char.ToLowerInvariant(this.scanner.Peek()) == 'x')
{
    char ch = this.scanner.Read();
    builder.Clear();
    ReadHexNum(builder);

    if (8 >= builder.Length)
    {
        return Convert.ToUInt32(builder.ToString(), 16);
    }
    else if (16 >= builder.Length)
    {
        return Convert.ToUInt64(builder.ToString(), 16);
    }
    else // Convert to JsonArray? or not support?
    {
        //JsonArray ja = new JsonArray();
    }
}

...
}

Object keys can be null

The key of a Json Object can be null. This behavior is not consistent with the JSON specifications.

JsonValue.AsNumber and JsonValue.AsString is affected by current culture

As far as I have understood, the textual representation of JSON numbers is not supposed to be affected by the current culture. For example it should always use a decimal period, even if the current culture uses decimal comma instead. LightJson does not seem to behave that way, due to the use of versions of ToString() and TryParse() which uses the current culture.

Some examples of the current behaviour, with culture "sv-SE":

  1. new JsonValue("1.0").AsNumber returns 0
  2. new JsonValue(0.5).AsString returns "0,5"

The following pull request changed that in the version of LightJson embedded in StyleCop.Analysers: DotNetAnalyzers/StyleCopAnalyzers#2442
The code might still not comply with the specification in http://json.org completely, but it can at least serve as a starting point if you would like to make LightJson more standards compliant.

Add clone method

Add Clone method to JsonValue, JsonObject, and JsonArray to allow for deep and shallow copies of Json values.

Offering some flexibility regarding "relaxed" syntax

Hi @MarcosLopezC,

After running into a variety of problems shipping a single binary that worked across numerous runtime environments (including .NET Core scenarios), the StyleCop Analyzers project is now looking at switching to an embedded copy of LightJson rather than depending on Json.NET. However, since this change is targeting a stable release branch, it was essential for us to not break existing users who could be relying on certain aspects of the relaxed syntax allowed by Json.NET, specifically:

Since we took the time to implement this required functionality for LightJson, I wanted to make you aware of the work in case you were interested in bringing it back into the core library. πŸ˜„

Decouple JsonReader and JsonWriter

JsonReader and JsonWriter have too many responsibilities. Their task should be split into two new different object: JsonParser and JsonSerializer. This would result in JsonReader and JsonWriter being more generic; which would make then suitable to be used by other classes to do quick JSON reading or writing.

Add repeatable serialization option.

Right now a JsonValue can sometimes produce different JSON strings when serialized. This caused by the way the JsonObject is serialized. By serializing the items within a JsonObject is alphabetical order, we can be sure that we'll always produce the same JSON string for any given JsonValue.

Incorrect `JsonParseException` for some control characters

From the official JSON specification, section 9 (emphasis mine):

A string is a sequence of Unicode code points wrapped with quotation marks (U+0022). All code points may be placed within the quotation marks except for the code points that must be escaped: quotation mark (U+0022), reverse solidus (U+005C), and the control characters U+0000 to U+001F. There are two-character escape sequence representations of some characters.

JsonReader checks for invalid control characters using char.IsControl(), and from its documentation:

The Unicode standard assigns code points from \U0000 to \U001F, \U007F, and from \U0080 to \U009F to control characters.

In other words, there is a range of characters which are designated Unicode control characters (and thus return a positive result from char.IsControl()) which are not deemed control characters according to the JSON standard. These characters will therefore not be escaped by many JSON serializers, which may cause an invalid JsonParseException to be thrown when the JSON contains them.

Of course this is all very unlikely, and of course therefore it just happened to me while consuming a JSON API and I spent the last few hours debugging the problem (turns out, \u007f doesn't quite show up in string output!).

EDIT: From the top of my head, as a suggested fix, I think replacing char.IsControl(c) with c <= '\u001f' should do the trick.

Add strict and non-strict conversion methods.

Add methods to JsonValue such as ToBoolean, ToInt, ToNumber, ToObject, etc. These method will be used for non-strict conversions. The casting operators will be used for strict conversion.

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.