question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Flatten Complex Json structure

See original GitHub issue

I 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:open
  • Created a year ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Cinchoocommented, Apr 22, 2022

found the issue, applied fix. released v1.2.1.48 (beta1)

Sample fiddle: https://dotnetfiddle.net/SDY3ql

2reactions
Cinchoocommented, Apr 6, 2022

Applied fix, released ChoETL.JSON.Core v1.2.1.45-beta2.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found