2

I need the following output

{hello = "world", test=aobjectname}

I have tried doing a enum{aobjectname} in c# and [JsonConverter(typeof(StringEnumConverter))]

Anyone else with a good idea how I might get the wanted output. The stuff i tried gives either test=1 or test="aobjectname".

0

1 Answer 1

2

That would not be valid JSON. String-values in JSON have to be in quotes. So test:"aobjectname" is the correct output, and no JSON serializer in the world will give you any output without those quotes.

JSON is a language. Languages have specifications. And the JSON language specification states, that a JSON object follows this structure:

Object structure

It also states, that a string value follows this structure:

String structure

If you violate those principles, then you no longer have JSON, but something of your own making, which is based on JSON. Which, in rare cases, can be fine. But you do need to know the sacrifice you are making: This is a language of your own design, so you will need to supply all the tooling around that language, including, but not limited to: Serializers and deserializers, MIME types, validators, etc.

In short, your object should look like this:

{hello: "world", test: "aobjectname"}

or

{hello: "world", test: 1}

By the way, if you need to convert "aobjectname" back to the enum value, you can do this by using the Enum.Parse method.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.