TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: My first open-source project release – RandomJson

56 点作者 mangatmodi大约 6 年前

8 条评论

ben509大约 6 年前
Congrats on the release!<p>I&#x27;d recommend mentioning &quot;fuzz testing&quot; and &quot;fuzzing&quot; in the description to help people find it.<p>Simple and Sample are very close in spelling.<p>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.<p>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:<p>1. atoms<p>2. homogenous arrays (same type of all elements)<p>3. heterogeneous arrays (element X has type Y, bounded length)<p>4. homogenous objects (same value type for all elements)<p>5. heterogeneous objects (key X has type Y, required + optional keys)<p>6. alternatives<p>Implement those and you probably cover any structure someone could throw at it. You&#x27;ll also want to make it easy to distinguish between required and optional keys.<p>If you take a page from QuickCheck[2], it&#x27;s nice to be able to implement a &quot;reduce&quot; feature. The idea is you produce something complex that breaks it, and simplify it to find a minimal test case.<p>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.<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;UnitedIncome&#x2F;json-syntax&#x2F;blob&#x2F;master&#x2F;json_syntax&#x2F;pattern.py" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;UnitedIncome&#x2F;json-syntax&#x2F;blob&#x2F;master&#x2F;json...</a><p>[2]: <a href="https:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;QuickCheck" rel="nofollow">https:&#x2F;&#x2F;hackage.haskell.org&#x2F;package&#x2F;QuickCheck</a><p>Versions of QuickCheck exist in many languages, e.g. <a href="https:&#x2F;&#x2F;github.com&#x2F;HypothesisWorks&#x2F;hypothesis-java" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;HypothesisWorks&#x2F;hypothesis-java</a>
评论 #19746791 未加载
bmaupin大约 6 年前
Nice work!<p>I&#x27;d recommend adding a license to make it easier for other people to contribute (if that&#x27;s something you&#x27;d like): <a href="https:&#x2F;&#x2F;help.github.com&#x2F;en&#x2F;articles&#x2F;licensing-a-repository" rel="nofollow">https:&#x2F;&#x2F;help.github.com&#x2F;en&#x2F;articles&#x2F;licensing-a-repository</a>
评论 #19747695 未加载
ivanche大约 6 年前
Congratulations, I hope you&#x27;ll release many more projects! A small suggestion: show examples of generated JSON alongside the source code.
评论 #19746621 未加载
hendry大约 6 年前
I&#x27;ve been using <a href="https:&#x2F;&#x2F;github.com&#x2F;yields&#x2F;phony" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;yields&#x2F;phony</a> lately for my random JSON needs.
michaelmior大约 6 年前
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.
tlarkworthy大约 6 年前
See also <a href="https:&#x2F;&#x2F;www.json-generator.com" rel="nofollow">https:&#x2F;&#x2F;www.json-generator.com</a> for random data from a JSON schema
jedimastert大约 6 年前
Mods: Can you remove the anchor from the link?
评论 #19746998 未加载
lichtenberger大约 6 年前
Great, I&#x27;ll use it for testing :-)