Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Am trying to convert json to csv. the json that i use is a complex json with deep nested arrays and child objects. Converting json -> xml -> dtatable ->csv is not working as am missing some of the hierarchies in this approach.

Could any one suggest some approach for the conversion?

thisis the part of the sample json that i use:

{
    "ParentRoot": {
        "Root1": [
            {
                "Value1": {
                    "innervalue1": "value",
                    "innervalue2": "value",
                    "innervalue3": "value",
                    "innervalue4": "value",
                    "innervalue5": "value",
                    "innervalue6": "value",
                    "innervalue7": "value"
                }
            }
        ],
        "Root2": {
            "Value2": {
                "innervalue1": "value",
                "innerArray1": {
                    "innerarrayvalue1": "value",
                    "innerarrayvalue2": "value",
                    "innerarrayvalue3": "value"
                },
                "innerArray2": {
                    "innerarrayvalue1":"value",
                    "innerarrayvalue2": "value",
                    "innerarrayvalue3": "value",
                    "innerarrayvalue4": "value",
                    "innerarrayvalue5": [
                        {
                            "childarrayValue": "value",
                            "childarrayValue2": "value"
                        },
                        {
                            "childarrayValue": "value",
                            "childarrayValue2": "value"
                        } ],

                    "other value": null
                }
            },
            "Root2child": [
                {
                    "innerValue": "value",
                    "innervalue2": "value",
                    "root2child": {
                        "innerValue": "value",
                        "innerValue1": "value",
                        "innerValue2": "value",
                        "innerValue3": "value"
                    },
                    "innerValue2": [
                        {
                            "inervalue3": "value",
                            "inervalue4": "value",
                            "inervalue5": "value",
                            "inervalue6": "value",
                            "inervalue7": "value",
                            "inervalue8": "value",
                            "inervalue9": "value",
                            "inervalue10": "value",
                            "inervalue11": "value",
                            "inervalue12": "value",
                            "inervalue13": "value",
                            "inervalue14": "value",
                            "inervalue15": "value",
                            "inervalue16": "value",
                            "inervalue17": "value",
                            "inervalue18": "value",
                            "inervalue19": "value",
                            "inervalue20": "value",
                            "inervalue21": "value",
                            "inervalue22": "",
                            "inerArray": {
                                "inerArrayValue": "value",
                                "inerArray": {
                                    "innerArrayElement": "value",
                                    "innerArrayElement1": "value"
                                },
                                "innerArrayValue2": [
                                    {
                                        "element": "value"
                                    }
                                ]
                            }
                        }
                    ]
                }
            ]
        }

        }

    }


What I have tried:

Tried differret logics but nothing helped
Posted
Updated 30-Jun-17 11:21am
Comments
F-ES Sitecore 5-Apr-17 7:10am    
What is the CSV file going to look like?

1 solution

There is no need for this much type conversion,
Quote:
Converting json -> xml -> dtatable ->csv is not working
You can simply convert the JSON document to a CSV document. For that, you need 2 libraries, 1 that would convert from JSON to runtime objects, then another that maps those runtime objects to CSV document.

We are aware of the Json.NET library, then there is another library written to convert the objects to CSV; Simple and fast CSV library in C#[^], have a look at the coding examples then write them in your own application.

And as for your type conversion, why doesn't that work? I think that does, here is a proof for that, the same conversion was marked as answer on this thread, JSON string to CSV and CSV to JSON conversion in c# - Stack Overflow[^]
 
Share this answer
 
Comments
Divya RS 7-Apr-17 5:23am    
Thanks Afzaal. I will
try this and see

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900