Hacker News new | past | comments | ask | show | jobs | submit login
Show HN: My first open-source project release – RandomJson (github.com/mangatmodi)
56 points by mangatmodi on April 25, 2019 | hide | past | favorite | 14 comments



Congrats on the release!

I'd recommend mentioning "fuzz testing" and "fuzzing" in the description to help people find it.

Simple and Sample are very close in spelling.

The sample makes sense, but a big use case for this would be testing APIs, and in that case, a JSON object is commonly modelled after the attributes of a class. So in that scenario, simply randomizing the keys would just blow up, which is not useful for testing. The kinds of errors you usually want to catch are small glitches.

I needed to describe the patterns that JSON could take when converting to and from native types, and I did that here [1] so it might be a useful structure to consider. But, roughly, you have several common cases:

1. atoms

2. homogenous arrays (same type of all elements)

3. heterogeneous arrays (element X has type Y, bounded length)

4. homogenous objects (same value type for all elements)

5. heterogeneous objects (key X has type Y, required + optional keys)

6. alternatives

Implement those and you probably cover any structure someone could throw at it. You'll also want to make it easy to distinguish between required and optional keys.

If you take a page from QuickCheck[2], it's nice to be able to implement a "reduce" feature. The idea is you produce something complex that breaks it, and simplify it to find a minimal test case.

You might go both ways... generate a valid pattern and add crap to it to see how tolerant it is. Or possibly start with reasonable length strings and make it possible to make them longer and longer.

[1]: https://github.com/UnitedIncome/json-syntax/blob/master/json...

[2]: https://hackage.haskell.org/package/QuickCheck

Versions of QuickCheck exist in many languages, e.g. https://github.com/HypothesisWorks/hypothesis-java


@ben509 thanks for amazing suggestions. I plan to add multiple features in next few days.


Nice work!

I'd recommend adding a license to make it easier for other people to contribute (if that's something you'd like): https://help.github.com/en/articles/licensing-a-repository


Thanks, I have added MIT license now.


Congratulations, I hope you'll release many more projects! A small suggestion: show examples of generated JSON alongside the source code.


Agree completely. When it comes to OSS I'd say: documentation, documentation, documentation. Specifically in your case, a detailed explanation of the API would also be really handy :)


I agree with you both. Developers hate documentation but I would add plethora of documentations and examples in next few days.


I've been using https://github.com/yields/phony lately for my random JSON needs.


Looks interesting. It would be helpful if you could show more examples of the JSON this produces. I can guess from the code, but it would be nice if this were explicit.


See also https://www.json-generator.com for random data from a JSON schema


Mods: Can you remove the anchor from the link?


My bad, I should have been careful when I submitted the post


Great, I'll use it for testing :-)


[flagged]


Actually, it's Kotlin.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: