Click here to Skip to main content
16,020,512 members
Home / Discussions / C#
   

C#

 
AnswerRe: Need to create next button Pin
Gerry Schmitz16-Oct-23 5:16
mveGerry Schmitz16-Oct-23 5:16 
GeneralRe: Need to create next button Pin
Member 1611639316-Oct-23 6:17
Member 1611639316-Oct-23 6:17 
GeneralRe: Need to create next button Pin
Dave Kreskowiak16-Oct-23 7:19
mveDave Kreskowiak16-Oct-23 7:19 
AnswerRe: Need to create next button Pin
RedDk16-Oct-23 6:49
RedDk16-Oct-23 6:49 
QuestionTransfer data between MFC Application and c# application using NamedPipe Pin
manoharbalu13-Oct-23 1:37
manoharbalu13-Oct-23 1:37 
AnswerRe: Transfer data between MFC Application and c# application using NamedPipe Pin
Richard Andrew x6413-Oct-23 2:28
professionalRichard Andrew x6413-Oct-23 2:28 
AnswerRe: Transfer data between MFC Application and c# application using NamedPipe Pin
JudyL_MD13-Oct-23 5:05
JudyL_MD13-Oct-23 5:05 
QuestionCreating a JSON File from a CSV file in C# Pin
Member 1611347712-Oct-23 2:19
Member 1611347712-Oct-23 2:19 
Apologies but this is going to be a "How to" question rather than a technical question. I am very new to C# and using Json. I have a CSV file as follows:

Edit - I did manage to find some code here - https://qawithexperts.com/article/c-sharp/convert-csv-to-json-in-c/465 - not sure if this is suitable for my goal as it seems to be a simple convert.

    Time	         Control_Code	Metric	Organisation	Value	DateTime
 

    2018-10-21T00:08:03 JKX           3721      AD450          20   2018-10-21T00:08:00
    2018-10-21T00:08:03 BHY           1234      HG650          88   2018-10-21T00:08:00
I need to produce multiple JSON output files from that csv in the following format example:

    {
        "Time":"2018-10-21T00:08:03",
        "Control_Code": "JKX",
        "metrics": [
            {
                "Metric": 3721,
                "Organisation":"AD450",
                "Value": 20,
                "Datetime":"2018-10-21T00:08:00"
            },
            {
                "Metric": 1234,
                "Organisation":"HG650",
                "value": 88,
                "datetime":"2018-10-21T00:08:00"
            }
            
        ]
    }

Now the extra problematic part on top of this is that there is a requirement where only one Control_Code may be used per Json.
Each Json generated must contain a single Control_Code and all related metric values in the metrics array. So the csv will need to be scanned for each different Control_Code and then produce an output for that specific Control_Code and then do the same for any subsequent Control_Codes.

So for example a different Json would be produced with a different Control_Code (from the same csv file) - Example (notice different Control_Code other values will of course change as well, but just providing an example).

    {
        "Time":"2018-10-21T00:08:03",
        "Control_Code": "BHY",
        "metrics": [
            {
                "Metric": 3721,
                "Organisation":"AD450",
                "Value": 20,
                "Datetime":"2018-10-21T00:08:00"
            },
            {
                "Metric": 1234,
                "Organisation":"HG650",
                "value": 88,
                "datetime":"2018-10-21T00:08:00"
            }
            
        ]
    }

Thanks for any advice/information in advance.

AnswerRe: Creating a JSON File from a CSV file in C# Pin
OriginalGriff12-Oct-23 2:29
mveOriginalGriff12-Oct-23 2:29 
AnswerRe: Creating a JSON File from a CSV file in C# Pin
jschell12-Oct-23 5:17
jschell12-Oct-23 5:17 
AnswerRe: Creating a JSON File from a CSV file in C# Pin
Gerry Schmitz12-Oct-23 8:36
mveGerry Schmitz12-Oct-23 8:36 
GeneralRe: Creating a JSON File from a CSV file in C# Pin
OriginalGriff12-Oct-23 9:07
mveOriginalGriff12-Oct-23 9:07 
GeneralRe: Creating a JSON File from a CSV file in C# Pin
Gerry Schmitz12-Oct-23 9:28
mveGerry Schmitz12-Oct-23 9:28 
GeneralRe: Creating a JSON File from a CSV file in C# Pin
OriginalGriff12-Oct-23 10:20
mveOriginalGriff12-Oct-23 10:20 
GeneralRe: Creating a JSON File from a CSV file in C# Pin
jschell13-Oct-23 7:09
jschell13-Oct-23 7:09 
QuestionItemObservableCollection Pin
rex648-Oct-23 7:34
rex648-Oct-23 7:34 
AnswerRe: ItemObservableCollection Pin
Gerry Schmitz8-Oct-23 7:55
mveGerry Schmitz8-Oct-23 7:55 
QuestionHow do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work4-Oct-23 11:32
Rod at work4-Oct-23 11:32 
AnswerRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Richard MacCutchan4-Oct-23 20:55
mveRichard MacCutchan4-Oct-23 20:55 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work5-Oct-23 2:38
Rod at work5-Oct-23 2:38 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Richard MacCutchan5-Oct-23 2:43
mveRichard MacCutchan5-Oct-23 2:43 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work5-Oct-23 3:24
Rod at work5-Oct-23 3:24 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work5-Oct-23 3:54
Rod at work5-Oct-23 3:54 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Richard MacCutchan5-Oct-23 4:18
mveRichard MacCutchan5-Oct-23 4:18 
AnswerRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
jschell5-Oct-23 5:48
jschell5-Oct-23 5:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.