JsonDataSource Conditional Expressions: !s.Disabled Fails, Requires s.Disabled==false When Using json instead of POCOs

When we were passing a POCO this would work:

<<if [MyProperty.Data.Any(s => !s.Disabled)]>>

When we changed to pass an interface (Data changed to a List instead of List), properties in sub interfaces could not be found so we decided to try and pass it as Json with JsonDataSource but then we get the error:

System.InvalidOperationException: Tag 'if' is not well-formed. A conditional expression should return a Boolean value.

and need to change to

<<if [MyProperty.Data.Any(s => s.Disabled==false)]>>

What’s the best way to approach this? And why is not !s.Disabled work when using other than POCO?

Please let me know if you’ll need any additional information.
GroupDocs.Assembly version 24.12.0

@oskarj

What is happening

  • When the data source is a POCO the expression is compiled against the actual .NET type (bool Disabled). The C# unary operator ! is therefore understood and the template works.
  • JsonDataSource does not deserialize the JSON into a POCO; it creates a dynamic object (JObject/JToken). The expression engine used by Assembly evaluates the condition on those dynamic values. The unary ! operator is not supported for a JToken/dynamic value, so the parser throws
System.InvalidOperationException: Tag 'if' is not well‑formed. A conditional expression should return a Boolean value.

Hence you must use an explicit Boolean comparison (s.Disabled == false or s.Disabled != true).

How to make it work reliably

  1. Ensure the JSON field is a proper JSON boolean ("Disabled": true / "Disabled": false).

  2. Use the equality form in the template, e.g.:

    <<if [MyProperty.Data.Any(s => s.Disabled == false)]>>
    

    or, if you prefer a negation style:

    <<if [MyProperty.Data.Any(s => s.Disabled != true)]>>
    
  3. If you need the ! syntax, convert the JSON to a POCO before passing it to the template, e.g.:

    var list = JsonConvert.DeserializeObject<List<MyImplementation>>(json);
    editor.DataSource = new JsonDataSource(list);
    

    (or use ObjectDataSource with the POCO list).

  4. Upgrade – the latest GroupDocs.Assembly release contains a small fix that improves handling of boolean values in JsonDataSource. If you can, move to the newest version and retest.

What we need to verify

  • A minimal JSON sample that reproduces the error (show the Disabled field).
  • The interface definition (IMyInterface) you are using with JsonDataSource.
  • The exact stack trace (if any) beyond the “Tag ‘if’ is not well‑formed” message.

Providing those details will let us confirm whether the issue is purely the expression‑parser limitation or if there is an underlying bug that needs to be logged.