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.

Help converting a complex json object

See original GitHub issue

Hi,

I have a json object, its not complex but what I want to end up, is a little difficult for me to understand how to do this. The standard JSON object (represented by a typescript interface) is this

{
  "_embedded": {
    "record": {
      "name": "CompanyA",
      "meta": {
        "address": "6 some street",
        "stateCountry: "NY, USA"
      }
    }
  },
  "pageData": {
    "pagination" : {
      "page": 1,
      "totalPages": 1
    }
  }
}

I want to end up with the following, represented by a typescript class

export class Item {
   name: string // this comes from __embedded/record/name
   address: string // this comes from __embedded/record/meta/address
   state: string // this comes from __embedded/meta/stateCountry (split by coma, FIRST part)
   country: string // this comes from __embedded/meta/stateCountry (split by coma, SECOND part)
  pagination : Pagination 
}

export class Pagination {
    page: number //this comes from __embedded/pageData/pagination/page
    totalPages: number //this comes from __embedded/pageData/pagination/totalPages
    hasNext: boolean // this uses the above 2 properties to work out if there is a nextPage, true/false
}

Any help really appreciated

Thanks

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
iangregsondevcommented, Apr 9, 2019

Sorry @emyann , I think that was a comment I left previously, I actually deleted it because sure enough, it was as easy as that.

Although it got it on iteretee

  totalPages: iteratee => iteratee.page.totalPages,
1reaction
iangregsondevcommented, Apr 9, 2019

That was perfect! Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

54. Convert Nested JSON Object Response To ... - YouTube
There are several ways of extracting values from JSON responses. We have already learnt to extract values from JSON responses using JSON ......
Read more >
How Convert Complex Json String to Object - java
Try to change all your class to public (including your additionalinfo. It may help. As I know some of JSON parser do not...
Read more >
How to Deserialize a Complex JSON Object in C# .NET
In this article, we are gonig to learn how to deserialize a complex JSON object using C# as our language of choice.
Read more >
Data Extraction: Parse a 3-Nested JSON Object and ...
We can use the requests package for this purpose. To get the data as a JSON output, we call the **request.get **method. The...
Read more >
Extract Nested Data From Complex JSON
Never manually walk through complex JSON objects again by using this function. We're all data people here, so you already know the scenario....
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