[Feature request] Provides play.api.data.Form.toJson

We can convert JSON to Form (https://github.com/playframework/playframework/blob/master/framework/src/play/src/main/scala/play/api/data/Form.scala#L393).

However, we can’t convert Form to JSON.

What I am doing at the moment is: form.fill(data).data. Then, I serialize data, which is Map[String, String], to JSON. This approach, however, serializes an array to, for example, images[0], images[1], and so on.

It’d be really helpful if we can serialize form to JSON (because it would reuse the unbind methods).

For more context: In a form, I use JSON as its main data. The form submits JSON to Play, and, vice versa, I use the same JSON to populate the form. So, a two-way serialization will be helpful.

If this seems like a good improvement, I’d love to make this improvement to Play.

Thank you!

Never mind. I think this requires way too much change to solve this problem properly. Because Mapping[T] is tightly coupled with Map[String, String].

It is easier for me to just do a hack that converts Map[String, String] to JsObject.