The JSON value could not be converted to System.String. Path: $[1].Interests[1].Meta[9].Content | LineNumber: 0 | BytePositionInLine: 10073. Error

AG Mohamed 1 Reputation point
2021-10-15T12:32:59.027+00:00
public Class Emp{

public string Name  { get; set; }


  [Column(TypeName = "jsonb")]
 public List<Section> Sections { get; set; }

}

public Class Section{

   public string Booking { get; set; }


 [Column(TypeName = "jsonb")]
  public List<Interest> Interests { get; set; }

}

public Class Interests{

 public string Title { get; set; }

 public List<Meta> Meta { get; set; }


 public List<WithAlt> Images { get; set; }
}

public Class Meta{

         public string Type { get; set; }

        public string Content { get; set; }

}

public Class WithAlt{

         public string content { get; set; }

        public string Alt { get; set; }

}

I fetch data from the above table

Emp while fetching the data I got
The JSON value could not be converted to System.String. Path: $[1].Interests[1].Meta[9].Content | LineNumber: 0 | BytePositionInLine: 10073. Error

When I manually add the value to database bellow

 {
        "Booking": "",
        "Interests":[
    {
        "Title":"",

       "Meta":[
`         {
             "Type" : " ",

              "Content" : " "


     `   }
       ],

      "Images" : [
         {
            "content" : " ",
            "alt" : " "

         }

    ]


     }
],         

}

it will not throw the error

Are there any way to define the default value to the above fields using code first approach

when I initialize Sections property like

public List<Section> Sections { get; set; }={};

it shows the following error

Can only use array initializer expressions to assign to array types. Try using a new expression instead.

Entity Framework Core
Entity Framework Core
A lightweight, extensible, open-source, and cross-platform version of the Entity Framework data access technology.
752 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,927 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,029 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Karen Payne MVP 35,441 Reputation points
    2021-10-15T15:12:16.313+00:00

    See the following for setting a default value for a property


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.