Possible to generate arbitrary json objects? #33
-
Hi I am using this in a rather unusual way currently to fuzz via HTTP. I am sending json and one field can be a json object with basically any key variation. So I am wondering what is the smartest way to do this. Is a grammar based mutator the best way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 27 replies
-
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. |
Beta Was this translation helpful? Give feedback.
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.