-1

I am working on a project in which i am getting a getting data from backend via api and i need to parse in using ramda. i am not sure how to do it .can anyone help me parse both the data given below

{
    "data": [
        {
            "id": 60009001,
            "userFullName": "",
            "gender": "male",
            "depositDone": 1,
            "familyId": 60009001
        }
    ]
}

 [
        {
            "id": 60009001,
            "gender": "male",
           
        }
    ]

i'm getting this data from backend and i only need the field "familyId" in first case and "gender" in second case. How can i parse it using ramda.

Deepak
  • 143
  • 2
  • 10
  • First of all, please show us what you've tried yourself. Second, it's quite unclear what distinguishes your first case from your second. Third, *why* do you need to parse it "using Ramda"? What do you think Ramda will offer you that vanilla JS will not? I'm one of the founders of Ramda, and I think it offers a lot in many circumstances. But what specifically should it offer here? – Scott Sauyet Aug 24 '20 at 12:27
  • i'm using ramda in graphql . and the above two cases are different in sense that the backend is not giving the tag data as in first case ..if you can help me parse it using ramda .please help – Deepak Aug 24 '20 at 12:39
  • Ramda is a library; it can't do anything that you cannot do yourself using JS. But depending upon what you're trying to do, it might possibly make it cleaner, more performant, simpler-to-maintain. But first we need to know what it is you want to do, and I'm afraid that's not clear. And you really need to show some effort of your own first. StackOverflow is a Question & Answer site, not a code-writing service. Try it on your own (with or without Ramda) and show us where you get stuck. – Scott Sauyet Aug 24 '20 at 12:51
  • If you're having a hard time writing more detailed requirements, try starting with the following, which looks like it will give the right answer to your two cases, and try fixing it up to cover your more general requirements: `const parse = (d) => Array.isArray(d) ? 'male' : 60009001` – Scott Sauyet Aug 24 '20 at 12:56

1 Answers1

0

Something along these lines should satisfy the requirement:

const { project, propOr } = R
const sampleData = {
  data: [
    {
        id: 60009001,
        userFullName: "",
        gender: "male",
        depositDone: 1,
        familyId: 60009001
    }
  ]
}

const result = project(['id', 'gender'], propOr([], 'data', sampleData))
console.log(result)
<script src="https://cdnjs.cloudflare.com/ajax/libs/ramda/0.27.1/ramda.min.js"></script>
Chad S.
  • 6,252
  • 15
  • 25