How to convert a nested json to a flat csv in jq

How to convert a nested json to a flat csv in jq

By : user3040352
Date : November 26 2020, 06:18 AM
hope this fix your issue I need to convert this json into a flat csv , Looks like you want the following :
code :
.Data[] | [.ID, .Marchio.ID , .Marchio.Codice, .Marchio.Descrizione , .Codifica.CodEan] | @csv

Share : facebook icon twitter icon
Generic method to convert a flat JSON array to nested JSON

Generic method to convert a flat JSON array to nested JSON

By : unaior
Date : March 29 2020, 07:55 AM
Does that help If you use Json.Net, you can do this conversion in a generic way using the LINQ-to-JSON API (JObjects). The idea is to parse the JSON array and add all the individual items to a dictionary keyed by Id. Then, loop over the dictionary items, and for each one, try to look up the parent. If the parent is found, add the item to the parent's items array (creating it if needed). Otherwise, add the item to the root array. Along the way, remove the depth property from each item, since you don't seem to want that in the output. Lastly, just dump the root array to string to get the final result.
code :
var dict = JArray.Parse(json)
    .ToDictionary(jo => (string)jo["Id"], jo => new JObject(jo));

var root = new JArray();

foreach (JObject obj in dict.Values)
    JObject parent;
    string parentId = (string)obj["ParentId"];
    if (parentId != null && dict.TryGetValue(parentId, out parent))
        JArray items = (JArray)parent["items"];
        if (items == null)
            items = new JArray();
            parent.Add("items", items);

    JProperty depth = obj.Property("depth");
    if (depth != null) depth.Remove();

jq: How to convert flat json into nested one

jq: How to convert flat json into nested one

By : Thatsakhorn Suwanjir
Date : March 29 2020, 07:55 AM
I wish this help you I've been trying to re-arrange a pretty flat json into structure with more depth, so far without any success. Here's my source data: , jq solution:
code :
jq '[group_by(.service_name)[] 
    | .[0].service_name as $name 
    | { name: $name, 
        data: map({ date: .time, 
                    details: {event, version}}) 
      }]' jsonfile
    "name": "cart",
    "data": [
        "date": "2017-12-21 07:21:00",
        "details": {
          "event": "Success",
          "version": "9ff24c4"
    "name": "prices",
    "data": [
        "date": "2017-12-21 07:24:00",
        "details": {
          "event": "Success",
          "version": "61f4u8e"
        "date": "2017-12-21 07:23:00",
        "details": {
          "event": "Fail",
          "version": "21c2f7d"
Convert nested Json to flat Json with parentId to every node

Convert nested Json to flat Json with parentId to every node

By : user2007710
Date : March 29 2020, 07:55 AM
around this issue You could take an iterative and recursive approach by using a function which takes an array and a parent id for the actual level.
If a property starts with child, it calls the function again with the actual _id and pushes all items to the result set.
code :
function getFlat(array, parentid) {
    return array.reduce((r, o) => {
        var temp = {};
        Object.entries(o).forEach(([k, v]) => {
            if (k.startsWith('child')) {
                r.push(...getFlat(v, o._id));
            } else {
                temp[k] = v;
        temp.parentid = parentid;
        return r;
    }, []);

var data = [{ child1: [{ _type: "EntityChild1", name: "Test222", _id: 2 }], child2: [{ _type: "EntityChild2", name: "Test333", _id: 3, child2_child1: [{ _type: "EntityChild2_1", name: "Test444", _id: 6, child2_child1_child1: [{ _type: "EntityChild2_1_1", name: "Test555", _id: 7 }] }] }], _type: "EntityParent", name: "Test000", _id: 1, child3: [{ _type: "EntityChild3", name: "Test111", _id: 4 }], child4: [{ _type: "EntityChild4", name: "Test666", _id: 5 }] }],
    flat = getFlat(data, -1);

.as-console-wrapper { max-height: 100% !important; top: 0; }
How can I convert a nested part of a JSON object to dot-chained flat JSON?

How can I convert a nested part of a JSON object to dot-chained flat JSON?

By : creezi smith
Date : March 29 2020, 07:55 AM
I hope this helps you . You evidently already know the solution to the second part of the problem, so here is a solution to the first part:
code :
# linearize all paths of the input object or array
def dotkeys:
  def stringify: map(tostring) | join(".");
  . as $in
  | reduce paths(scalars) as $p (null;
     ($in|getpath($p)) as $v
     | setpath([$p|stringify]; $v));

def chain(key):
 .[key] |= dotkeys ;

  "level1a": "value",
  "level1b": {
    "level2a.level3a": "nestedvalue",
    "level2b": "value"
unable to convert nested json to flat json using javascript

unable to convert nested json to flat json using javascript

By : Samster357
Date : October 08 2020, 07:00 AM
This might help you You can simply us Array.flatMap() or Array.map() methods to return a new array. As per your requirement, both will work. Array.flatMap() & Array.map()
code :
var data = [{"_score":0.5753642,"_type":"data","_id":"686","_source":{"mainData":"subset","data":"vehicle","name":"subset_vehicle","fields":["number","id","chasis"],"dataset":"chasis"},"_index":"vehicle"},{"_score":0.575,"_type":"data","_id":"687","_source":{"mainData":"subset1","data":"vehicle1","name":"subset_vehicle1","fields":["number","id","chasis"],"dataset":"chasis1"},"_index":"vehicle"},{"_score":0.57,"_type":"data","_id":"686","_source":{"mainData":"subset","data":"vehicle","name":"subset_vehicle","fields":["number","id","chasis"],"dataset":"chasis"},"_index":"vehicle"}]

var a = data.flatMap(d => {
  d._source._id = d._id;
  return d._source;

Related Posts Related Posts :
  • how to write r.headers from different urls into one json?
  • Parsing JSON concurrently - panic of runtime error (decoding related)
  • How to fix "Subscript out of range" error in XML HTTP Request
  • Splitting nested arrays as separate entities
  • Trying to parse the JSON and create an extracted JSON
  • NiFi JoltTransformJson outputs only first record
  • Dynamic (But known as another key value) JSON Decoding with Swift Decodable
  • How to use map on json response returned by a REST API with ReactJs
  • How to read a file line by line and then output all lines compounded with sth in jq?
  • java.lang.RuntimeException: Failed : HTTP error code : 400 : Bad Request
  • How to check jq result is null or not?
  • CloudFormation - How to use Sub intrinsic function?
  • VBA: Nested JSON Object Structure for UK Bank Holidays - Run Time Errors 13, 438 and 449
  • JasperReports. Using value from parent json in child table
  • Output key value pairs as JSON from T-SQL query
  • Getting key value pairs with linux server
  • Modifying settings.json in vscode to add shell escape flag to pdflatex in latex workshop
  • Unable to render data into grid column using JSON results
  • JSON decode failed
  • How to remove brakets on Json respone
  • How to parse JSON-input
  • JSON syntax for getting personal query ID
  • detecting 400 response without JSON response
  • Newtonsoft deserializing Json incorrectly
  • Getting _jsonparsefailure with valid json in logstash
  • How to send Map as String in POST request in flutter?
  • Difficulty fetching json data from API using Angular
  • Reading JSON data for my select query in SQL Server
  • AWS CloudFormation Template (JSON) to Create EC2 - Unexpected Error
  • How to concat multiple fields to same line with jq
  • Issue sending POST request from Swift
  • Storing JSON in BigQuery
  • How to get the value of a key in a JSON?
  • How to validate JSON input in Go
  • Extracting specific and latest data from http webserver using golang
  • Incorrect type. Expected "object"
  • json_to_record with embedded encoded json in PostgreSQL >= 10
  • Nested json extract from powershell
  • Parsing Json using Golang
  • Type 'number' is not assignable to type 'string'. How to cast number to string
  • kubectl - format the resource quota values in json format
  • Initializing and inserting nested JSON data in Golang?
  • Open JSON files in PhpStorm built-in web server
  • Extract Badge ID from JSON in .gitlab-ci.yml
  • Sharing Json Schema files among projects with versioning
  • Export Json data to an excel file using Angular 4
  • Return an empty array instead of null with golang for json return with gin
  • can Kafka connect value conveter (JSONConverter) can be used to convert GPB?
  • read json and access multiple keys
  • Spark How to get number of Keys changed in two JSONS in Scala?
  • Break JSON in pager "less"
  • How to filter Map in Flutter?
  • Convert hashmap to simple object in Groovy
  • Not extracting json properly using json4s
  • How do I display JSON data in my tableView when objects have the same value?
  • Where I can parse IoT data in Azure so I can afterwards save it to SQL DB
  • How to unmarshal this json string
  • What's wrong with my JSON?
  • JSON parsing problem in BlackBerry
  • GWT: How can I use JsonpRequestBuilder to handle a Json response of a list
  • shadow
    Privacy Policy - Terms - Contact Us © festivalmusicasacra.org