C # search in JSON without deserialization

I have a JSON text file in my universal Windows 10 application, which is quite large (> 40 MB). This is an array of such objects:

[{"prop1": "X", "prop2": "hjk", "prop3": "abc"},
 {"prop1": "X", "prop2": "lmn", "prop3": "def"},
 {"prop1": "Y", "prop2": "opq", "prop3": "abc"},
 {"prop1": "Y", "prop2": "rst", "prop3": "def"}]

I want to be able to retrieve only a few lines, for example, every object that contains the string "abc" in any property, as well as the "Y" on prop1.

Expected Result:

[{prop1: "Y", prop2: "opq", prop3: "abc"}]

I am afraid of deserializing all of this, as it may be too much for lower-level devices such as phones. Can this be done using JSON.NET?

+4
source share
1 answer

, JsonTextReader. , . :

using (var fs = File.OpenRead(path))
using (var textReader = new StreamReader(fs))
using (var reader = new JsonTextReader(textReader))
{
    while (reader.Read())
    {
        if (reader.TokenType == JsonToken.StartObject)
        {
            var obj = JObject.Load(reader);
            Debug.WriteLine("{0} - {1}", obj["id"], obj["name"]);
        }
    }
}
+6

Source: https://habr.com/ru/post/1618190/


All Articles