示例#1
0
        public JToken JTokenTranserializerImpl(object source)
        {
            var jtokenEmitter = new JTokenEmitter();

            ValueSerialier.SerializeValue(jtokenEmitter, source, source?.GetType() ?? typeof(object));
            return(jtokenEmitter.Root);
        }
示例#2
0
        public object Search(string expression, object json)
        {
            var jtokenEmitter = new JTokenEmitter();

            _serializers.ValueSerialier.SerializeValue(jtokenEmitter, json, json?.GetType() ?? typeof(object));
            var transformOutput = _jmespath.Transform(jtokenEmitter.Root, expression);

            using (var stringWriter = new StringWriter())
            {
                using (var jsonWriter = new JsonTextWriter(stringWriter)
                {
                    CloseOutput = false
                })
                {
                    transformOutput.WriteTo(jsonWriter);
                }

                var jsonText = stringWriter.GetStringBuilder().ToString();
                return(_serializers.YamlDeserializer.Deserialize <object>(jsonText));
            }
        }