mikhail-barg / jsonata.net.native

.Net native implementation of JSONata query and transformation language (http://jsonata.org)
MIT License
40 stars 6 forks source link

Option to have single line or indented string as output from Eval #27

Open mikanygTC opened 4 months ago

mikanygTC commented 4 months ago

In the current implementation of JsonataQuery.Eval(string) the result is always indented and formatted.

I suggest a minor change either as optional parameter or overload, to specify if output string is indented or single line.

When moving json over the network wire, a compact format can often be a better choice.

mikhail-barg commented 4 months ago

Hi, @mikanygTC thank you for the proposal.

Still I'm not sure how to include it in a library. Adding an optional argument to existing method would break binary compatibility. And adding an override looks like an overkill.

If you find it useful, you may implement an extension in your code, using same code and JToken.ToFlatString() instead of JToken.ToIndentedString()

mikanygTC commented 4 months ago

Well an extension method would work and did something like this to get the behavoir. Suggested this change so others could benefit from it.

I understand that optional parameter is a breaking change, and would be the less ideal approach to include it in the lib. If the library would offer the choice for consumers to specify the preferred output formatting, I don't see the overload of the Eval method as being overkill, but maybe I'm missing some insights.

I'll go with the extension method, but still suggest to have some option to specify output format directly included in the library.