JSON是否有等价的XSLT ?它允许我对JSON进行转换,就像XSLT对XML所做的那样。
当前回答
XSLT支持JSON,见http://www.w3.org/TR/xslt-30/#json
XML uses angular brackets for delimiter tokens, JSON uses braces, square brackets, ... I. e. XML's fewer token recognition comparisons means it's optimized for declarative transformation, whereas more comparisons, being like switch statement, for speed reasons assume speculative branch prediction that imperative code in scripting languages is useful for. As direct consequence, for different mixes of semi-structured data, you may want to benchmark XSLT and javascript engines' performance as part of responsive pages. For negligible data payload, transformations might work just as well with JSON without XML serialization. W3's decision ought to be based on better analysis.
其他回答
说缺乏工具就意味着缺乏需求,这只是在回避问题。这同样适用于Linux中的X或Y支持(为什么要为这样一个少数操作系统开发高质量的驱动程序和/或游戏呢?为什么要关注一个大型游戏和硬件公司不会开发的操作系统?)可能需要使用XSLT和JSON的人最终会使用一种有点琐碎的解决方法:将JSON转换为XML。但这不是最优解,对吧?
当您有一个原生JSON格式,并且希望在浏览器中以“所见即所得”的方式编辑它时,XSLT将是一个非常合适的解决方案。用传统的javascript编程来实现这一点可能会让人头疼。
事实上,我已经实现了一种“石器时代”的XSLT方法,使用子字符串解析来解释javascript的一些基本命令,比如调用模板、子进程等。当然,使用JSON对象实现转换引擎要比实现成熟的XML解析器来解析XSLT容易得多。问题是,要使用XML模板转换JSON对象,您需要解析模板的XML。
要将JSON对象转换为XML(或HTML、文本或其他内容),您需要仔细考虑语法以及需要使用哪些特殊字符来标识转换命令。否则,您将不得不为自己的自定义模板语言设计一个解析器。走过这条路后,我可以告诉你,它并不漂亮。
Update (Nov 12, 2010): After a couple of weeks working on my parser, I've been able to optimize it. Templates are parsed beforehand and commands are stored as JSON objects. Transformation rules are also JSON objects, while the template code is a mix of HTML and a homebrew syntax similar to shell code. I've been able to transform a complex JSON document into HTML to make a document editor. The code is around 1K lines for the editor (it's for a private project so I can't share it) and around 990 lines for the JSON transformation code (includes iteration commands, simple comparisons, template calling, variable saving and evaluation). I plan to release it under a MIT license. Drop me a mail if you want to get involved.
JSONiq就是这样一个标准,而Zorba是一个开源的c++实现。JSONiq也可以看作是添加了JSON作为原生数据类型的XQuery。
我使用骆驼路由marshal(xmljson) ->到(xlst) -> marshal(xmljson)。足够高效(虽然不是100%完美),但简单,如果你已经在使用Camel。
我最近发现了一个我喜欢的JSON样式工具:https://github.com/twigkit/tempo。非常容易使用的工具——在我看来,使用它比使用XSLT容易得多——不需要XPATH查询。
XSLT支持JSON,见http://www.w3.org/TR/xslt-30/#json
XML uses angular brackets for delimiter tokens, JSON uses braces, square brackets, ... I. e. XML's fewer token recognition comparisons means it's optimized for declarative transformation, whereas more comparisons, being like switch statement, for speed reasons assume speculative branch prediction that imperative code in scripting languages is useful for. As direct consequence, for different mixes of semi-structured data, you may want to benchmark XSLT and javascript engines' performance as part of responsive pages. For negligible data payload, transformations might work just as well with JSON without XML serialization. W3's decision ought to be based on better analysis.
推荐文章
- 查询JSON类型内的数组元素
- 将JSON字符串转换为HashMap
- 将JsonNode转换为POJO
- Json_encode()转义正斜杠
- c# vs Java Enum(适合c#新手)
- 如何写一个JSON文件在c# ?
- 如何在XSLT中实现if-else语句?
- 在序列化和反序列化期间JSON属性的不同名称
- 为什么PHP的json_encode函数转换UTF-8字符串为十六进制实体?
- Ajax会调用什么样的响应,比如'for (;;);{json data}的意思?
- 在JavaScript中将JSON字符串解析为特定对象原型
- 使用Jackson将JSON字符串转换为漂亮的打印JSON输出
- jQuery。由于转义了JSON中的单引号,parseJSON抛出“无效JSON”错误
- 用c#解析JSON
- XPath查找节点是否存在