-
Notifications
You must be signed in to change notification settings - Fork 68
Open
Labels
Description
Is there a way to retrieve a whole document, not just some of it's properties or collections?
For a json file from a docs' sample:
{
"selected_user": { "id": 1, "name": "Phil", "age": 40, "city": "NY" },
"temperature": 23.45,
"note": "this is a test"
}
How could one retrieve it a as a whole into an instance of a class?
public class Settings
{
public User SelectedUser { get; set; }
public double Temperature { get; set; }
public string Note { get; set; }
}
Metadata
Metadata
Assignees
Labels
Projects
Milestone
Relationships
Development
Select code repository
Activity
[-]How to get whole document[/-][+]How to get whole document?[/+]ttu commentedon Aug 8, 2018
There is no way to retrieve whole JSON as a document/object.
Root level properties are documents, so if you want to retrieve settings as a single object, you have to put it under property:
Deilan commentedon Aug 8, 2018
@ttu Thanks for the response! May I request a feature to retrieve a whole document then? :)
ttu commentedon Aug 9, 2018
Yes, I can add it.
How about if I just modify the GetItem-method, so if it is called with empty string as a key, then it would return the whole JSON?
Deilan commentedon Aug 12, 2018
@ttu There are 3 points why I think it should be done in a different way:
""
(empty string) - is a valid JSON token's name. In other words{ "": 0 }
is a valid JSON. Hence we have an ambiguation between retrieving""
property and the whole document. Besides it could break backward compatibility.I'd say there should be a dedicated method for getting the whole document. Something like
GetRoot
orGetDocument
.GetRoot
seems more appropriate to me because at the outermost level JSON could be an array as well as an object.ttu commentedon Aug 13, 2018
Thanks for the input and yes, you are correct.
First I was thinking also
GetRoot
-method, but because of lack of time, thought that adding functionality toGetItem
would have been the fastest way to implement this. As you pointed out, it wouldn't have even worked that way.Have to think this littlebit more, but maybe
GetRoot
has to returnRoot
-object that can either have aDocumentCollection
or a single item.AbdulmueezEmiola commentedon Aug 28, 2020
Hello,
I saw this issue opened and I was wondering whether It has been fixed. If not, I will like to attempt to provide a solution to it
ttu commentedon Aug 30, 2020
Thanks @AbdulmueezEmiola! This hasn't been fixed/implemented yet. I started some solution, but then forgot this...
Pushed the implementation I had done to https://github.com/ttu/json-flatfile-datastore/tree/add-getroot. Commit: 0258e7e
Based on what you had in mind you can continue that or if you have some better idea, provide a new solution :)
MostHated commentedon Nov 5, 2020
If someone does provide a solution for this, it would be appreciated if this could be updated. I just started using this today, got it all worked out and implemented, only to find out I could not simply get all records. : /
Resolves ttu#19
Resolve ttu#19 - Added get root to IDataStore and changed location of…