0

I have .json files stored in AWS S3 bucket. I use the function OpenStreamAsyncto get a specified file and I want to read it and arrange the items according to the way I expect them to be in the .json file but into excel (I use EEPlus).

What is the best practice to do so?

user4675862
  • 35
  • 1
  • 6
  • Break this into steps and view each step as unrelated to the others. First, read your JSON into a collection of some objects. Write that code as if it doesn't matter what you're going to do with it next. Separately, write code to write a collection of objects to Excel. For that second part, it doesn't matter where the objects came from - JSON or somewhere else. This isn't really an answer, just a pointer in the right direction. If you separate it into separate problems you can solve them separately. You might already know how to do one, but not the other. – Scott Hannen Dec 10 '18 at 14:24

1 Answers1

1
{ "name":"John", "age":30, "car":null }

1) create a class that matches your JSON you could use http://json2csharp.com/

public class RootObject
{
    public string name { get; set; }
    public int age { get; set; }
    public object car { get; set; }
}

2) use Json.NET to deserialize

Install Package

PM> Install-Package Newtonsoft.Json


Code to serialize JSON
var group2 = JObject.Parse(yourjson).ToObject<RootObject>();
  1. Create your EEPlus document with your objects
Micah Armantrout
  • 6,781
  • 4
  • 40
  • 66