Custom Field Type Module - JSON Validation Error

I have created a forge app using the custom field type module. When submitting the field data I am presented with this JSON validation error. “The value must be a JSON object.”. I believe the problem may be with my manifest/JSON schema, as I am not too familiar with writing my own JSON schemas.

modules:
    jira:customFieldType:
        - key: custom-field-configurable-validation
          name: Custom Field
          description: A basic custom field with a configurable validation.
          type: object
          formatter:
               expression: "`${value.object}`"
          schema:
            properties: 
              values:
                type: array
                items:
                  type: object
                  properties:
                    objVal1: 
                      type: string
                    objVal2:
                      type: string
                    objVal3:
                      type: string
                  required: [ "objVal1", "objVal2", "objVal3" ]
          validation:
              expression: value == null
              errorMessage: The value is invalid
          contextConfig:
              resource: main
              layout: native
          edit:
              resource: edit

Here is an example of what the field data looks like on submit.
{
“values”:[
{
“objVal1”:“val1”,
“objVal2”:“val2”,
“objVal3”:“val3”
}
]
}

I’m also new to all of this, and haven’t done an array of objects… but I’ll try to help. It looks like maybe in your <CustomFieldEdit> you might need to designate the parent array for each objVal# being set. In your case it looks like the array name is “object” so maybe something like <TextField name="object.objVal1" ...> ? Similarly the “required” may need that specified as well.

Although, I feel like I saw somewhere that an array was limited to the type of objects it could hold so I’m not sure how objects work inside the array for these. I’ll try to find that reference. I only think this because I initially also wanted to do an array of objects but ended up doing an array of strings and putting JSON formatted strings inside of it to parse as JSON when necessary (which I don’t think I would have done unnecessarily, but I could have just been doing it wrong too and was able to get strings to work so I could move on :upside_down_face: ).

EDIT: @HALECHRISTOPHER, I think this comment here made me believe it wasn’t possible, so I moved on. If you do get an array of objects to work I would be interested. Maybe @kkercz could confirm?

The array name in the manifest should have been “values”, like in the JSON example :upside_down_face:. I edited the original post.

I did try setting the name props to values.objVal1 and removed the required from manifest. Neither made a difference.

From the comments on the linked post it looks like to me that a nested array of objects is not supported. I believe the method suggested is to have separate arrays for each property? I will give that a try.

That was my takeaway from the thread as well. For my purposes, I worried about keeping the separate arrays in proper order, especially since I wanted to sort them based on different values as new entries were added (it’s own rabbit hole). Because of that, I did a single array of strings, with each entry being a JSON formatted string. Then when working with the values would parse it. e.g., <Text>values.map(x => (JSON.parse(x)).objVal1</Text> . The trade off I think is having to search exact strings in the JQL search. Depending on the number of objects you need to store (there is a limit) this could be worked around by having additional properties that stores each object property separately just for search purposes, and then another that store the object strings together for the object itself. But I think it really just depends on what you are storing and how it gets used.

After switching to separate array for each prop, it is now working properly. Although I would like to see support for arrays of objects in the future. If it is supported, I hope to see some clarification from Atlassian on how it can be configured. This would allow for more useful custom fields and easier development IMO.
Doing it this way forces you to have to map an array for each property when displaying the field values. And if you want to allow optional fields, it becomes even more cumbersome. Having a single object in a single array is much more streamlined.

@DavidPezet1 I am curious how or if your validation works with the method you described? I can only imagine it would be a nightmare to create validation expressions on an array of JSON strings vs an array of objects.

@HALECHRISTOPHER For my purposes, I’m just using dates and numbers, so the fields kinda handle “validation” on their own. I haven’t added any more sophisticated validation (yet). I would think though that you should be able to add a property to the object that you can set within your edit code to perform any validation necessary, then check that property in your manifest validation expression. This might even let you do something like an “error” property that you can set with a string for the error, then the validation could check expression: error != null ; errorMessage: error (but I haven’t tried).

For me, I wanted to be able to sort by dates, or sort by numbers, depending on different situations. So updating the corresponding index between several different arrays seemed way more awful than using JSON.parse() on the entries of a single array. But I’m sure it totally depends on the use case.