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.

Merge duplicate struct definitions

See original GitHub issue

Where there are multiple properties which reuse the same nested properties, the corresponding struct definition should be flattened. Take the following JSON:

{
   "filter":{
      "sitereference":[
         {
            "value":"shshs"
         }
      ],
      "transactionreference":[
         {
            "value":"3-64-25205"
         }
      ]
   }
}

Expected output:

type AutoGenerated struct {
	Filter Filter `json:"filter"`
}

type FilterAutoGenerated struct {
	Value string `json:"value"`
}

type Filter struct {
	Sitereference        []FilterAutoGenerated `json:"sitereference"`
	Transactionreference []FilterAutoGenerated `json:"transactionreference"`
}

Actual output:

type AutoGenerated struct {
	Filter Filter `json:"filter"`
}

type Sitereference struct {
	Value string `json:"value"`
}

type Transactionreference struct {
	Value string `json:"value"`
}

type Filter struct {
	Sitereference        []Sitereference        `json:"sitereference"`
	Transactionreference []Transactionreference `json:"transactionreference"`
}

Issue Analytics

  • State:open
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
michaelsanfordcommented, May 26, 2019

I just encountered this and came to file this exact issue.

I’d be willing to take a look (given the tag).

Incidentally, this tool is a boon to anyone using a public API that produces extremely verbose structures. Thank you! ❤️ 🙏

1reaction
Capable-Disk4147commented, Jul 15, 2021

@michaelsanford Are you still working on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

SwiftUI duplicate in struct and delete and merge them by ...
I have requirement string for the drinks, eg two glass of coke, one no ice and another with ice. I want if no...
Read more >
How can I concatenate or merge two structures? - MathWorks
I would like to merge two structures into a new structure containing all the fields of the two original structures.
Read more >
Duplicate Fields - CUE lang
CUE allows duplicated field definitions as long as they don't conflict. ... For structs, fields are merged and duplicated fields are handled recursively....
Read more >
Remove duplicates from sorted array - GeeksforGeeks
Given a sorted array, the task is to remove the duplicate elements from the array. Examples: Input : arr[] = {2, 2, 2,...
Read more >
URL Canonicalization and the Canonical Tag | Documentation
When a site has duplicate content, Google chooses the canonical URL. Learn more about canonical URLs and how to consolidate duplicate URLs.
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