50

I'M SO PROUD, I WROTE A FULLY-FUNCTIONAL JSON PARSER!

I used some data from the devRant API to test it :D
(There's a lot of useful tests in the devRant API like empty arrays, mixed arrays and objects, and nested objects)

Here's the devRant feed with one rant, parsed by Lua!

You can see the type of data (automatically parsed) before the name of the data, and you can see nested data represented by indentation.

The whole thing is about 200 lines of code, and as far as I can tell, is fully-featured.

Comments
  • 1
    Can you also post then json lua?
  • 1
    @asgs Sorry, I don't know what you mean
  • 3
    @iamavalos Thanks! Super soon on the source.

    And yah I thought it fit there but I'm afraid to use the actual rant category these days.

    Fuck some of the hardass users here XD
  • 4
    @FrodoSwaggins Now that I'm in the parsing mood, I might do YAML.

    For sure, not XML though. That seems a little hard.

    CSS Maybe. Like a simple CSS parser. None of that like... :nth-child(3) shit
  • 3
    @iamavalos It seems that way, more and more. Originally we just hated on people that posted facebook memes, which, is mean, but IMO, a little justified. Now you get crucified if you mislabel your most.

    I'm just gonna quickly write the Lua -> JSON (Stringifier) and then I'll update the GH repo and mention you. Probably won't make another post about it here.
  • 3
    @iamavalos That's true, and it shouldn't be that way.

    People are abrasive online no matter what, I have found.
  • 3
  • 2
    @SauceBoss There's OOP, but it isn't fully-featured OOP.

    Its actually better than the JS OOP, especially if you learn how to work the metatables (Which allows you to do operator overloading.

    The syntax is definitely... unique, however. Quite a bit different from how you'd do OOP in other languages. The ":" operator is definitely confusing.

    Have a look,

    https://www.lua.org/pil/16.1.html
  • 1
    @SauceBoss The syntax really is great, it reminds me of SQL, but somehow better.

    ES6 (Actual classes and inheritance within the syntax) makes OOP in JS a bit nicer but I still prefer Lua as a language
  • 2
    @SauceBoss Lua itself is still pretty high level, arguably higher level than PHP.

    But when you get to working with c/c++ AND Lua together (Which isn't required, by the way. Just very common), you'll learn about some pretty low-level items like pointers and stack machines. That's where the fun really is. Buyer beware, it's also where the headaches live.
  • 2
    @SauceBoss At the moment, I'm working on expanding the Lua standard library. I want to make it comparable to the Python or even Java std lib.

    Most of the things I have actually done with Lua in the past have been in Minecraft because of the Computer Craft mod, which is what introduced me to Lua
  • 0
    @SauceBoss It doesn't have a standard one, like npm or pip, but there's one that is pretty much de-facto, and it has the best name of any package manager:

    luarocks

    It gets even better knowing Lua is Brazilian Spanish for moon. It's a double pun.
  • 1
    @FrodoSwaggins (I assume, quite luckily) I have never worked with YAML past some very basic data, so I do not know the horrors.

    I'd actually be interested in hearing some, to be honest. I might be up for the challenge. I'm on a high after completing this.
  • 2
    As 'easy' as JSON parsers are, fuck me they are fun to build.

    Does your parser support .JSONC or just JSON?
  • 2
    @lxmcf I don't know what JSONC is
  • 4
    @AlgoRythm json with comments
  • 1
    @lxmcf I would probably work comment ignoring into the code pretty easily. I'll do it later tonight and let you know how it goes. I also want to optimize it by using string.byte instead of 1-length substrings.
  • 1
    @lxmcf

    Support for JSONC

    Top: usage

    Middle: implementation

    Bottom: output
  • 0
    @iamavalos @SauceBoss @lxmcf Docs page for the JSON module:

    https://algorythm-dylan.github.io/l...
  • 1
    Really interesting! We (as in a coding dojo) made one in Ruby yesterday. The idea was being able to parse a stream of JSON, for exemple a very large file. Code available here: https://gitlab.com/epfl-dojo/...
  • 1
    @ponsfrilus 68 lines and works from a stream? That's so good it hurts!
  • 2
    @AlgoRythm well, the main idea is here, it was a one hour dojo so there is still a lot to do for a usable thing. But we learn the way to stream parse and it was the point !
  • 0
    @ponsfrilus Aha, very nice! I don't know Ruby, but after starting at the code for a bit it didn't seem like it actually returned any data, but I thought that perhaps it was just some Ruby magic I didn't understand.

    It does look pretty good though.
  • 0
    @AlgoRythm check this out http://seriot.ch/parsing_json.php (found via HN - https://arp242.net/weblog/...). It might be relevant for you.
Add Comment