Flatten Complex Json structure
See original GitHub issueI have these line of code:
using (var r = new ChoJSONReader("data.json")
.Configure(c => c.ThrowAndStopOnMissingField = true)
.Configure(c => c.DefaultArrayHandling = true)
.Configure(c => c.FlattenNode = true)
.Configure(c => c.IgnoreArrayIndex = false)
.Configure(c => c.NestedKeySeparator = '.')
.Configure(c => c.NestedColumnSeparator = '.'))
{
var dt = r.AsDataTable();
Console.WriteLine(dt.DumpAsJson());
}
and my json:
{
"BrandId": "998877665544332211",
"Categories": [
"112233445566778899"
],
"Contact": {
"Phone": [
{
"Value": "12346789",
"Description": {
"vi": "Phone"
},
"Type": 1
},
{
"Value": "987654321",
"Description": {
"vi": "Phone"
},
"Type": 1
}
]
}
}
My expected output:
[
{
"BrandId": "998877665544332211",
"Contact.Phone.Value": "12346789",
"Contact.Phone.Description.vi": "Phone",
"Contact.Phone.Type": 1,
"Category": "112233445566778899"
},
{
"BrandId": "998877665544332211",
"Contact.Phone.Value": "987654321",
"Contact.Phone.Description.vi": "Phone",
"Contact.Phone.Type": 1,
"Category": "112233445566778899"
}
]
After running code, I got the output like this:
[
{
"BrandId": "998877665544332211",
"Contact.Phone.0.Value": "12346789",
"Contact.Phone.0.Description.vi": "Phone",
"Contact.Phone.0.Type": 1,
"Contact.Phone.1.Value": "987654321",
"Contact.Phone.1.Description.vi": "Phone",
"Contact.Phone.1.Type": 1,
"Category0": "112233445566778899"
}
]
Thanks for your interest in the question Looking forward to hearing from you @Cinchoo
Issue Analytics
- State:
- Created a year ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
Flatten and unflatten complex/nested JSON objects
Use the JSON Flatten tool to normalize and flatten complex JSON objects by key name. The object can be ordered alphabetically, either ascending...
Read more >How to flatten multilevel/nested JSON? - python
It's working with the JSON that is given, I'm appending _ for flattening JSON instead of using 0 1 list indexing. from pprint...
Read more >How to Flatten A Complex Nested JSON Structure in ADF
1. In the source transformation option, select Document form as 'Array of documents' . This is how your source data looks like: Results[]...
Read more >How to Flatten Deeply Nested JSON Objects in Non- ...
The idea is that we scan each element in the JSON file and unpack just one level if the element is nested. We...
Read more >Python Pandas - Flatten nested JSON
In this article, let us consider different nested JSON data structures and flatten them using inbuilt and custom-defined functions.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
found the issue, applied fix. released v1.2.1.48 (beta1)
Sample fiddle: https://dotnetfiddle.net/SDY3ql
Applied fix, released ChoETL.JSON.Core v1.2.1.45-beta2.