Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fromJSON() with nested array #436

Open
berthetclement opened this issue Feb 23, 2024 · 0 comments
Open

fromJSON() with nested array #436

berthetclement opened this issue Feb 23, 2024 · 0 comments

Comments

@berthetclement
Copy link

berthetclement commented Feb 23, 2024

Hello,

I would like to read the content of a JSON file that is formatted either in "array" mode ([{"id": "79f4b5801", "owner": {"id": 251, "name": "titi toto"}}]') or in JSON mode without the "[]" ('{"id": "79f4b5801", "owner": {"id": 251, "name": "titi toto"}}').

With the square brackets, the result of the following code is ok :

good <- fromJSON('[{"id": "79f4b5801", "owner": {"id": 251, "name": "titi toto"}}]')
as.data.table(good)

id owner.id owner.name
1: 79f4b5801 251 titi toto

Now without square brackets :

bad <- fromJSON('{"id": "79f4b5801", "owner": {"id": 251,"name": "titi toto"}}')
as.data.table(bad)

id owner
1: 79f4b5801 251
2: 79f4b5801 titi toto

I don't have a solution for getting the right result without the square brackets, and for the moment I'm forced to use the paste0() to add square brackets.

it seems trivial but I haven't found, with the fromJSON() parameters, how to format the result correctly.

Could you give me an idea?

Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant