当前位置:网站首页>d合并json
d合并json
2022-08-02 22:42:00 【fqbqrr】
module combinejsonv3;
import std.file;
import std.stdio;
import std.json;
import std.array;
import std.algorithm.searching;
void main()
{
// 保存位置
JSONValue jsonResult;
jsonResult.array = [];
foreach (string filename; dirEntries(".", "*.json", SpanMode.shallow))
{
// 包含输出,忽略
if(canFind(filename, "output")) {
std.stdio.writeln("ignoring: " ~ filename);
continue;
}
// 按串读
string content = std.file.readText(filename);
// 按JSON解析
JSONValue j = parseJSON(content);
// 数组,则合并
if(j.type == JSONType.array) {
// 显示状态
std.stdio.writeln("processing JSON array from: " ~ filename);
jsonResult.array ~= j.array;
}
}
// 写至文件.
std.file.write("output-combined.json", jsonResult.toPrettyString);
}
可这样:
import std.stdio : writeln;
不与std.file冲突.
或这样:
import std;
void main() {
dirEntries(".", "*.json", SpanMode.shallow)
.filter!(f => !f.name.canFind("output"))
.map!(readText)
.map!(parseJSON)
.fold!((result, json) {
result ~= json.array; return result; })
.toPrettyString
.reverseArgs!(std.file.write)("output-combined.json");
}
边栏推荐
猜你喜欢

用了 TCP 协议,数据一定不会丢吗?

科研用Cholesterol-PEG-NHS,NHS-PEG-CLS,胆固醇-聚乙二醇-活性酯

无代码开发平台表单样式设置步骤入门课程

分库分表索引设计:二级索引、全局索引的最佳设计实践
![[TypeScript] Deep Learning of TypeScript Classes (Part 1)](/img/47/34954f1e01b844816d74f3ac556f9b.png)
[TypeScript] Deep Learning of TypeScript Classes (Part 1)

精心整理16条MySQL使用规范,减少80%问题,推荐分享给团队

TDengine 在中天钢铁 GPS、 AIS 调度中的落地

CWE4.8:2022年危害最大的25种软件安全问题

Controller层代码这么写,简洁又优雅!

I have been in the software testing industry for nearly 20 years, let me talk to you about today's software testing
随机推荐
centos7安装mysql8
IDEA 重复代码的黄色波浪线取消设置
脂溶性胆固醇-聚乙二醇-叠氮,Cholesterol-PEG-Azide,CLS-PEG-N3
[论文总结] 深度学习在农业领域应用论文笔记10
Software testing pen questions 1 (with answers)
图像识别从零写出dnf脚本关键要点
vscode 自定义快捷键——设置eslint
用于中文文本分类的中文停用词
The only way to go from a monthly salary of 10k to 30k: automated testing
【Unity】Unity开发进阶(七)双刃剑:扩展方法
多租户的多种实现方案
工业元宇宙的价值和发展
MySql查询某个时间段内的数据(前一周、前三个月、前一年等)
用了 TCP 协议,数据一定不会丢吗?
Word2Vec词向量训练、使用及可视化操作
resubmit 渐进式防重复提交框架简介
函数:计算组合数
Apache Doris 1.1 特性揭秘:Flink 实时写入如何兼顾高吞吐和低延时
Cholesterol-PEG-Acid,胆固醇-聚乙二醇-羧基保持在干燥、低温环境下
软件测试到底自学还是报班?