DevToys
DevToys copied to clipboard
JSON to Code
Is your feature request related to a problem? Please describe. As a web developer, it common to have to convert a large JSON to C# classes in order to consume certain web API.
Describe the solution you'd like Add a JSON to C#, TypeScript and Java tool.
Could I work on this?
With pleasure!
Some guidance:
- Feel free to make your own solution for the conversion, or take example on existing implementation on GitHub. Just be mindful of the license. I'd like to keep DevToys under MIT license, so I'd avoid anything that has a license requiring us to publish DevToys under the same than their.
- Keep things simple, for now. I'd prefer shipping a converter with a minimal set of languages and options for it than delivering a lot options right at the beginning. For example, for C#, I think the following options to start should be enough:
- Should array be treated as [] or List<T>
- Should properties support nullable values or not
- Follow the coding style guidance here: https://github.com/veler/DevToys/blob/main/CONTRIBUTING.md#coding
- Let's start with JSON to C# and TypeScript first. Let's see in a future iteration for other languages like Java, Python or C++
- Let's support Smart Detection feature. Here is an example: https://github.com/veler/DevToys/blob/d6cf9414110d9fecf4c2c44af8df74074ea1def4/src/dev/impl/DevToys/ViewModels/Tools/JsonFormatter/JsonFormatterToolProvider.cs#L29-L32
- When designing the UI
- Consider using the monaco editor like in Json Formatter or Json <> Yaml tool.
- If you need more than 3 options in the UI, consider an expandable one, like in Regex Tester tool
- Make sure to test the UI in compact mode, maximized window and small (width and height) window side.
Don't hesitate to ask questions here or ping me on Discord :) Thank you so much for wanting to participate :D
Visual Studio already has an option for this under the Edit menu.
@Jaiganeshkumaran , thank you :) What you're saying is true, but it lacks a few options to define, for example, whether we want PascalCase, camelCase, and more options that we can find on websites online. We're trying to bring the power of these online service into an offline app, not to limit ourselves to what Visual Studio already does.
Hi guys! Is there any chance to see Class to JSON converter? I'd love to use it for API testing
By Class to Json, to you mean generating mocked JSON value from a class definition?
Exactly. I see this as a input window for my C# class and (maybe) a JSON constructor where I can pick values I need in my JSON. I mentioned that because I often test my APIs by Postman and I always struggle with converting my API's input model into JSON especially a large ones. That initial conversion can be done by Swagger, but Swagger generates model as full as it can be, so I have to manually clean it and that can be very time consuming
I kinda implemented it with NJsonSchema on a sample console app but the output is messy, still have to port it to the app.
[December 2022 update]
This could be a potential paid feature for DevToys 2.0.
UX could be as simple as:
Input: JSON
Output: TypeScript, Python, Java, C#, PHP, C++, Ruby, Go, Dart, Rust, Swift
Settings: They would be specific to each output language selected. For example, for C#, we could allow to chose whether a [JSONProperty] attribute should be added.
support added with Devtoys.JsonToCSharp extension for DevToys 2.0.1