问题标签 [yajl]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
1 回答
234 浏览

python - Using json.loads v/s yajl.loads for reading a large JSON file in python

I am working with huge JSON files, with size ranging from 100-300 MB. Hence in order to save disk space (and computation time?), I converted the JSON file into a .json.gz file and proceeded like this :

json.loads didn't cause any issues with memory usage, but I would like to increase the speed, and hence I tried py-yajl (not to be confused with yajl-py, which I tried as well, but that took much more time since I was parsing the streamed JSON), like this :

But as I have seen on sites claiming that yajl is faster than json and simplejson libraries, I couldn't see an improvement in execution time. On the contrary, it took a bit more time as compared to json. Am I missing something here? In what cases, yajl is supposed to be faster than json/simplejson? Does the speed depend on the structure of a JSON file as well?

My JSON file looks like this :

I am aware that this is a subjective question and is likely to be closed, but I couldn't clear my doubts anywhere, and, at the same time, I would like to know about the difference b/w these libraries in more detail, hence asking here.

0 投票
0 回答
284 浏览

ruby - 如何使用 yajl-ruby 解析和过滤大 json 文件中的数据(2G 大小)

我需要从 json 文件(大约 2G 大小)中过滤掉一些数据。乔恩就像

在做了一些关于在 ruby​​ 中解析巨大 json 的研究之后,我找到了https://github.com/dgraham/json-streamhttps://github.com/brianmario/yajl-ruby,我尝试了 json_stream 大约需要 20 分钟,并且这个网站https://github.com/dgraham/yajl-ffi#performance

yajl-ruby 更快

使用 json_stream,我可以使用诸如 start_object/end_object/key/value 之类的回调来了解何时解析对象,然后对该对象进行一些处理并继续。

但是使用 yajl-ruby,我只找到一个名为“on_parse_complete”的回调。它的文档(https://www.rubydoc.info/github/brianmario/yajl-ruby/Yajl/Parser)说

然后我写了一段代码

我测试了小尺寸的样本 json 文件(

见开头给出的例子

)

但输出是#the whole JSON obj#(一次全部转储),而不是我想要的是逐个输出“数据”部分中的每个对象,就像我可以在“数据”中的每个obj之后得到json流一样" 被解析并输出,我可以对它做一些事情,比如检查每个 obj 是否是我想要的数据。

我的预期输出是:

起初,obj { "name":"Fred", "team":"football", "hobby":"climbing" } 在这个 obj 上做某事

然后 obj {"name":"Tony", "team":"basketball", "hobby":"fishing"} 在这个 obj 上做某事

然后 obj {"name":"alex", "team":"soccer", "hobby":"movies" } 在这个 obj 上做某事.....

可能我对这句话有一些误解

"它将传递一个参数,即从最后解析的 JSON 对象构建的 ruby​​ 对象"#

关于回调

“on_parse_complete”

在上面显示的文档中描述。

任何人都知道如何用 yajl-ruby 做到这一点?任何帮助表示赞赏。

0 投票
1 回答
135 浏览

ruby - Yajl 使用数组数据流式传输巨大的 json 文件并对每条记录进行操作

我有一个巨大的 json 文件,其中包含来自数据库的 json 记录的数组数据。下面说一下

我想流式传输文件并一次处理一条记录。请告知这是如何完成的。

我试过下面的代码。但它会打印整个数组,我关心的是内存使用情况,我想一次处理一条记录,因此无需将整个数组加载到内存中。

0 投票
1 回答
191 浏览

arrays - RPG YAJL 解析数组内的数组

RPG新手,我对如何做到这一点有点迷茫。“数据”是一个包含我需要的信息的数组,我可以解析它。然而,“cargoLoaded”是“data”数组中的一个数组,其中包含一个项目“cargoSensor1”。我需要 cargoSensor1 的值。

JSON 和下面我的部分代码(不包括数据区域)。

我要解析的 JSON(我需要值 cargoSensor1)

0 投票
2 回答
64 浏览

ibm-watson - 如何使用 YAJL 库读取 Watson Visual Recognition JSON Respsonse?

如何正确使用 Scott Klement 的 YAJL 库来读取 Watson Visual Recognition 的响应?json 对象如下所示:

现在我想从具有类 score_hierarchy 的类对象中获取值。我怎样才能到达 classes 数组?获取图像对象后,我找不到分类器继续...

0 投票
1 回答
119 浏览

json - YAJL JSON 解析

我正在尝试使用 YAJL 解析以下 JSON。YAJLGEN 在数据结构下方生成,但我面临的问题是数组的数量,例如:KEY、CUSTOMER 不固定。为响应中的每个字段返回这些数组。我试图避免为响应中的每个字段定义一个数组。

能否请您告知是否有更好的方法来阅读下面的 json 并解析动态数组。我尝试使用“yajl_array_loop”、“yajl_array_elem”,但由于某种原因我无法让它在我的程序中工作。提前致谢。


{ "errstatus": 400, "errors": { "Key": [ "The Key field is required." ], "客户": [ "客户字段为必填项。" ] } }

dcl-ds jsonDoc 合格;
errstatus packed(3) inz(0);
dcl-ds 错误;
num_KEY int(10) inz(0);
键 varchar(37) inz('') dim(1);
num_CUSTOMER int(10) inz(0);
客户 varchar(43) inz('') dim(2);
结束ds;
结束ds;