当前位置:网站首页>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");
}
边栏推荐
- 数字化转型巨浪拍岸,成长型企业如何“渡河”?
- 第十章 时序与延迟
- 程序员的七夕浪漫时刻
- 基于STM32的FLASH读写实验含代码(HAL库)
- ssm整合(三)Controller 和 视图层编写
- If the watermark according to how to realize the function
- Technology Sharing | How to do assertion verification for xml format in interface automation testing?
- 采用QT进行OpenGL开发(三)着色器编程
- MySQL 与InnoDB 下的锁做朋友 (四)行锁/记录锁
- [TypeScript] Deep Learning of TypeScript Classes (Part 1)
猜你喜欢
随机推荐
Cholesterol-PEG-Amine,CLS-PEG-NH2,胆固醇-聚乙二醇-氨基脂两亲性脂质衍生物
Web APIs BOM- 操作浏览器-Window对象
[TypeScript] Deep Learning of TypeScript Classes (Part 1)
刚安装完win10专业工作站版,系统变量中Path默认值有哪些?重新建一个“PATH”变量名,会覆盖掉原先的“Path”。
分库分表索引设计:二级索引、全局索引的最佳设计实践
创建型模式 - 抽象工厂模式AbstractFactory
MDL 内存描述符链表
用大白话解释“什么是ERP?” 看完这篇就全明白了
别再用Field注入了
centos7安装mysql5.7步骤(图解版)
智能电视竞争白热化,利用小程序共建生态突围
Towards a General Purpose CNN for Long Range Dependencies in ND
mysql 错误:The driver has not received any packets from the server.
微信小程序(一)
00 -- jieba分词
threejs 动态调整相机位置,使相机正好能看到对象
Broadcast platform, the use of the node generated captcha image, and validate
聚乙二醇衍生物4-Arm PEG-DSPE,四臂-聚乙二醇-磷脂
CTF命令执行题目解题思路
JS Date 时间戳 getTune data.parse 倒计时小程序