GithubHelp home page GithubHelp logo

json_events's Introduction

Hi! I am Ahmet Enes Bayraktar

✔️ I'm a Problem Solver who always pursues knowledge and experience but my title says Software Architect
✔️ I like building open-source tools that people can use
✔️ I am currently working on tools that help people to make games
✔️ You can reach me via:
    Email: [email protected]
    LinkedIn: https://www.linkedin.com/in/ahmet-enes-bayraktar
    Discord: aeb-dev#7034
    Reddit: u/aeb-dev
    Twitter: @aeb_dev
    Blog: aeb-dev.me
✔️ I love gaming

json_events's People

Contributors

aeb-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

sailcast e-tobi

json_events's Issues

Special Thanks

This package solve real world problems, I wonder why not Dart have this by default.

The fields containing numbers are not working correctly on the web

Hello, I'm currently using json_events version 1.2.0, and I'm experiencing a bug.

I've noticed an issue with integers and decimals. It works fine in all environments except on the web, where it doesn't function properly.

In my case, I noticed the issue when I realized that one of my fields named "size" contained -4294967276 instead of 20.
I had encountered an error before when using json_events on the web, related to the maximum size of an integer in JavaScript. So, I suspected that the issue I just experienced was specifically related to the web version.

To reproduce the issue, you can follow these steps:

Utilize json_events version 1.2.0.
Create or use a field named "size" in your JSON data.
Observe the value of "size" being -4294967276 instead of the expected value (e.g., 20) when running your code in a web environment.

Or simply test your example on an online editor (for example: zapp.run). You will see that all fields containing numbers are incorrect.

I hope to see a fix soon if possible. If there are any issues with understanding, please feel free to ask for more information about the bug I've reported.

Extra arrayElement after object in array

Having this json:

{"foo":[{"bar": "baz"}, null]}

I get this sequence of events:

  • JsonEventType.beginObject : null
  • JsonEventType.propertyName : foo
  • JsonEventType.beginArray : null
  • JsonEventType.beginObject : null
  • JsonEventType.propertyName : bar
  • JsonEventType.propertyValue : baz
  • JsonEventType.endObject : null
  • JsonEventType.arrayElement : null
  • JsonEventType.arrayElement : null
  • JsonEventType.endArray : null
  • JsonEventType.propertyValue : null
  • JsonEventType.endObject : null

After the object in the array an extra arrayElement with value null is emitted. This can't be ignored because there actually might be a null in the array.

Extra propertyValue after object property

When having a json like:

{"id":\"foo", "aaa": {}}

the sequence of events is:

  • JsonEventType.propertyName : id
  • JsonEventType.propertyValue : foo
  • JsonEventType.propertyName : aaa
  • JsonEventType.beginObject : null
  • JsonEventType.endObject : null
  • JsonEventType.propertyValue : null
  • JsonEventType.endObject : null

I guess the last propertyValue shouldn't be there.

Reading Map objects from JSON array

The use case that drew my attention to json_events is, that I download a large JSON array where I want to process each object in the array one after the other. Loading the whole JSON into memory for parsing is a no-go. I'm new to Dart/Flutter (coming mainly from C#, C++, Python, Ruby) so I was little bit surprised there was no streaming JSON parser (I'm so used to JSON.Net, I'm probably a little bit spoiled :-) So: json_events to the rescue! (Thanks for providing this!)

But using the JsonArrayTraverser / JsonObjectTraverser feels a little "bulky". Wouldn't it be nice, if you could simply get Map<string, dynamic> objects from a JSON-Stream with an array? Then json_serializable can be used to get the objects from it.

I did a quick test, if this is possible - see code below. (That's where I stumbled upon the other issues, I just posted).
Wouldn't something like this be a nice addition to json_events? If you like this idea, I can try to provide a PR for this. The code below is not yet complete. e.g. an array of arrays wouldn't work. So this would need a little bit more time to do it right with unit tests etc..

readJsonObjectAsMap(StreamIterator<JsonEvent> streamIterator) async {
  Queue<dynamic> objectStack = Queue<dynamic>();
  Map<String, dynamic> root = {};
  objectStack.addLast(root);
  String? currentProperty;
  JsonEvent? lastEvent;
  while (objectStack.isNotEmpty) {
    await streamIterator.moveNext();
    print("${streamIterator.current.type} : ${streamIterator.current.value}");
    switch (streamIterator.current.type) {
      case JsonEventType.propertyName:
        currentProperty = streamIterator.current.value;
        break;
      case JsonEventType.propertyValue:
        if (currentProperty != null) {
          objectStack.last[currentProperty] = streamIterator.current.value;
          currentProperty = null;
        }
        break;
      case JsonEventType.beginObject:
        Map<String, dynamic> newObject = {};
        if (currentProperty != null) {
          objectStack.last[currentProperty] = newObject;
        }
        else {
          objectStack.last.add(newObject);
        }
        currentProperty = null;
        objectStack.addLast(newObject);
        break;
      case JsonEventType.endObject:
        objectStack.removeLast();
        break;
      case JsonEventType.beginArray:
        List newArray = [];
        objectStack.last[currentProperty] = newArray;
        currentProperty = null;
        objectStack.addLast(newArray);
        break;
      case JsonEventType.endArray:
        objectStack.removeLast();
        break;
      case JsonEventType.arrayElement:
        // There's a bug that null array element is emitted after an object in an array
        if (lastEvent?.type != JsonEventType.endObject)
        {
          objectStack.last.add(streamIterator.current.value);
        }
        break;
    }
    lastEvent = streamIterator.current;
  }
  return root;
}

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.