Exemple #1
0
        public static SelectedValue[] SelectValues(TextReader json, string[] selectors, JSONSelectorOptions options)
        {
            if (null == json)
            {
                return new SelectedValue[0];
            }

            // Create tokenizer for the JSON text - this is fed to a Tree Walking Validator
            JSONTokenizer tokenizer = new JSONTokenizer(json);

            // Create an events object for the Tree Walker - events are fired as the walker
            // traverses nodes in the tree.
            JSONWalkingEvents events = new JSONWalkingEvents();

            // The selector subscribes to the Walker Events and selects the appropriate values from the
            // JSON tree.
            JSONSelector selector = new JSONSelector(events, selectors);

            // A JSON Tree Walker that validates the structure of the JSON and also fires events
            // while traversing the tree.
            JSONWalkingValidator walker = new JSONWalkingValidator();
            walker.Walk(tokenizer.GetEnumerator(), events);

            // Retrieve the values selected from the JSON.
            return selector.SelectedValues;
        }
Exemple #2
0
        public static SQLConstraint GenerateSQLConstraint(IDatabaseService db, Dictionary<string, Type> typeMappings, string json)
        {
            var tokenizer = new JSONTokenizer(new StringReader(json));

            var events = new JSONWalkingEvents();

            var constraint = new JSONToSQLConstraint(db, events, typeMappings);

            JSONWalkingValidator walker = new JSONWalkingValidator();
            walker.Walk(tokenizer.GetEnumerator(), events);

            return constraint.GenerateSQLConstraint();
        }