Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8553449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:39:16+00:00 2026-06-11T14:39:16+00:00

I have a JSON data source providing a list of hashes: [ { a:

  • 0

I have a JSON data source providing a list of hashes:

[
  { "a": "foo",
    "b": "sdfshk"
  },
  { "a": "foo",
    "b": "ihlkyhul"
  }
]

I use fromJSON() in the rjson package to convert that to an R data structure. It returns:

list(
  structure(list(a = "foo", b = "sdfshk"), .Names = c("a", "b")),
  structure(list(a = "foo", b = "ihlkyhul"), .Names = c("a", "b"))
)

I need to get this into an R data frame, but data.frame() turns that into a single-row data frame with four columns instead of a 2×2 data frame as expected. I lack the R-fu to do the transform from one to the other, though it looks like it should be straightforward.

Bonus points:

The actual problem is a bit more complex, because the JSON data source isn’t as regular as I show above. The objects it returns vary in type. That is, the field set in each can be one of a few different types:

[
  { "a": "foo",
    "b": "asdfhalsdhfla"
  },
  { "a": "bar",
    "c": "akjdhflakjhsdlfkah",
    "d": "jfhglskhfglskd",
  },
  { "a": "foo",
    "b": "dfhlkhldsfg"
  }
]

As you can see, the “a” field in each object is a type tag, indicating which other fields the object will have.

I’m not too particular how the solution copes with this.

It wouldn’t be horrible if the two object types were just mooshed together, so you get columns a, b, c, and d, and the rows simply have N/A or NULL values where the JSON source object doesn’t have a value for a given field. I believe I can clean the resulting data frame with subset(df, a == "foo"). I’ll end up with some empty columns that way, but it won’t matter to my program.

It would be better if the solution provides a way to select which JSON source rows go into the data frame and which get rejected, so the result has only the columns and rows actually required.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T14:39:17+00:00Added an answer on June 11, 2026 at 2:39 pm

    If you have a jagged list you want converted to a data.frame, you could use Hadley’s plyr’s rbind.fill. Saved my neck on a couple of occasions. Let me know if this is what you’re looking for. Notice that I modified your first example to include only “b” in the third element to make it jagged.

    > x <- list(
    +         structure(list(a = "foo", b = "sdfshk"), .Names = c("a", "b")),
    +         structure(list(a = "foo", b = "ihlkyhul"), .Names = c("a", "b")),
    +         structure(list(b = "asdf"), .Names = "b")
    + )
    > 
    > library(plyr)
    > do.call("rbind.fill", lapply(x, as.data.frame))
         a        b
    1  foo   sdfshk
    2  foo ihlkyhul
    3 <NA>     asdf
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an autocomplete field using local JSON data. $( #tags ).autocomplete({ source: get_items,
i have json data like this {GetStudentDetails: {TotalCount:5, RootResults:[ {city:West Chester,country:USA,state:PA ,student_id:100}, {city:Philly,country:USA,state:PA,student_id:101}, {city:Buffalo,country:USA,state:NY,student_id:102},
If I have JSON data such as: { datapoints:[ [null, 1234567890, point1], [null, 1234567890,
Is it typical or the preferred method to have JSON data embedded in a
I have a JSON data like this: { hello: { first:firstvalue, second:secondvalue }, hello2:
I have a JSON data store used for a combobox selection which is working
I have 5 view which have deferent json data , in all my 5
Let's say i have this json data. How to transform the tags to a
i have question about YAJLiOS parser... I have next json data : {{ body
I have a JSON-like data structure (which I don't want to change) that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.