a ‘primitive value’ or ‘StartObject’node was expected

In this spfx tutorial, I have explained how to fix the error ‘node of type ‘StartArray’ was read from the JSON reader when trying to read a value of a property; however, a ‘PrimitiveValue’ or ‘StartObject’ node was expected.’

A ‘PrimitiveValue’ or ‘StartObject’ node was expected

Recently, I was working on a SharePoint framework solution where I was inserting multiple values in a SharePoint list multi-select choice field column. While executing the code, I got the error “a ‘PrimitiveValue’ or ‘StartObject’ node was expected.”

The complete error looks like the below:

spfx error 'a 'PrimitiveValue' or 'StartObject' node was expected
spfx error ‘a ‘PrimitiveValue’ or ‘StartObject’ node was expected

Here I was using the below SharePoint list ‘Task management’ to insert items.

an unexpected 'startobject' node was found for property named

In the above SharePoint list ‘TaskManagement’ contains three columns:

  • Title(Single line of text)
  • Assignee(Single line of text)
  • Assignments (choice -mult selection enabled),

For this, I have created an spfx webpart solution ‘createSPListItem’, which contains these three fields like below.

error 'a 'PrimitiveValue' or 'StartObject' node was expected
error ‘a ‘PrimitiveValue’ or ‘StartObject’ node was expected

So here when we submit this form after filling it, we will get this error ‘a ‘PrimitiveValue’ or ‘StartObject’ node was expected.’ Because when we select multiple values in webpart, it comes as an array, but when we insert the value in the column of the SharePoint list, it is inserted as an array. But we need to insert the value as an object.

a 'startobject' node or 'primitivevalue' node with null value was expected
sharepoint framework unexpected error ‘a ‘PrimitiveValue’ or ‘StartObject’ node was expected

So the error is coming when we add the item to the SharePoint list column Assignments, this is the code:

private onSubmit = async (event: React.FormEvent<HTMLFormElement>): Promise<void> => {
    event.preventDefault();
    // Insert form data to SharePoint list
    const { title, assignee, assignments } = this.state;
    try {
      console.log(title);
      console.log(assignee);
      console.log(assignments);

      const list = await sp.web.lists.getByTitle('TaskManagement').items.get();
      console.log(list);
      await sp.web.lists.getByTitle('TaskManagement').items.add({
        Title: title,
        Assignee: assignee,
        Assignments:assignments 
      });
      this.setState({
        title: '',
        assignee: '',
        assignments: [],
        successMessage: 'Data added to SharePoint list successfully!',
      });
    } catch (error) {
      console.error('Error adding data to SharePoint list:', error);
    }
  };

To solve this error, we just need to insert the Assignments value as an object and the error will vanished. Also you can insert the value, to the SharePoint list.

private onSubmit = async (event: React.FormEvent<HTMLFormElement>): Promise<void> => {
    event.preventDefault();
    // Insert form data to SharePoint list
    const { title, assignee, assignments } = this.state;
    try {
      console.log(title);
      console.log(assignee);
      console.log(assignments);

      const list = await sp.web.lists.getByTitle('TaskManagement').items.get();
      console.log(list);
      await sp.web.lists.getByTitle('TaskManagement').items.add({
        Title: title,
        Assignee: assignee,
        Assignments:{results:assignments} 
      });
      this.setState({
        title: '',
        assignee: '',
        assignments: [],
        successMessage: 'Data added to SharePoint list successfully!',
      });
    } catch (error) {
      console.error('Error adding data to SharePoint list:', error);
    }
  };

When we fill out the form and click on submit button, the data is inserted to the SharePoint list successfully.

a 'startobject' node or 'primitivevalue' node with null value was expected
spfx unexpected error ‘a ‘PrimitiveValue’ or ‘StartObject’ node was expected

This is how we can resolve the error “a ‘startobject’ node or ‘primitivevalue’ node with null value was expected” by passing the object to a multi-selected choice column in the SharePoint list.

See also  error TS1192: Module has no default export [Solved]

Conclusion

In this spfx tutorial, we saw how to resolve the error ‘a ‘PrimitiveValue’ or ‘StartObject’ node was expected.’

  • a ‘primitive value’ node was expected
  • a ‘startobject’ node or ‘primitivevalue’ node with null value was expected
  • an unexpected ‘startobject’ node was found for property named

You may also like the following spfx tutorials:

>