Skip to content

Possible to generate arbitrary json objects? #33

Answered by teymour-aldridge
MTRNord asked this question in Q&A
Discussion options

You must be logged in to vote

As this is a context-free grammar, I think so. The other way I know of is to use a recursive mutator to generate an enum (most likely with the same structure as serde_json::Value) and then write a function to serialize it to a string (e.g. as https://github.com/bailion/compiler/blob/main/tests/generator/src/lib.rs does, but this becomes messy; JSON does have a much simpler grammar than that example).

There is a chapter on grammar-based mutators in the guide.

Replies: 1 comment 27 replies

Comment options

You must be logged in to vote
27 replies
@teymour-aldridge
Comment options

@loiclec
Comment options

@teymour-aldridge
Comment options

@MTRNord
Comment options

@teymour-aldridge
Comment options

Answer selected by MTRNord
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants