Convert JSON to csv in C#
- Given users.json as the json file
using (var csv = new ChoCSVWriter("users.csv").WithFirstLineHeader())
{
using (var json = new ChoJSONReader("users.json")
.WithField("Username")
.WithField("Sub", jsonPath: "$.Attributes[?(@.Name == 'sub')].Value", isArray: true)
.WithField("EmailVerified", jsonPath: "$.Attributes[?(@.Name == 'email_verified')].Value", isArray: true)
.WithField("GivenName", jsonPath: "$.Attributes[?(@.Name == 'given_name')].Value", isArray: true)
.WithField("FamilyName", jsonPath: "$.Attributes[?(@.Name == 'family_name')].Value", isArray: true)
.WithField("Email", jsonPath: "$.Attributes[?(@.Name == 'email')].Value", isArray: true)
.WithField("UserCreateDate")
.WithField("UserLastModifiedDate")
.WithField("Enabled")
.WithField("UserStatus")
)
{
csv.Write(json);
}
}
Like this:
Like Loading...
Related