@frogcat/ttl2jsonld

中文文档
0.0.11发布于 2026/10/15MITCommonJS零依赖近 30 天下载 8.1万

Turtle to JSON-LD converter for node.js and browser, no library dependencies

原始使用文档
文档目录13 节
  1. Demo
  2. Input Turtle
  3. Output JSON-LD
  4. Install
  5. node.js
  6. browser
  7. Usage
  8. node.js
  9. browser
  10. API
  11. For developers
  12. building
  13. testing

@frogcat/ttl2jsonld

Turtle to JSON-LD converter for node.js and browser, no library dependencies.

Demo

Online demo is available here.

With this converter, you can obtain Output JSON-LD from Input Turtle, as shown in JSON-LD 1.0 Specification .

Input Turtle

@prefix foaf: <http://xmlns.com/foaf/0.1/> .

<http://manu.sporny.org/about#manu> a foaf:Person;
  foaf:name "Manu Sporny";
  foaf:homepage <http://manu.sporny.org/> .

Output JSON-LD

{
  "@context": {
    "foaf": "http://xmlns.com/foaf/0.1/"
  },
  "@id": "http://manu.sporny.org/about#manu",
  "@type": "foaf:Person",
  "foaf:name": "Manu Sporny",
  "foaf:homepage": { "@id": "http://manu.sporny.org/" }
}

Install

node.js

$ npm install @frogcat/ttl2jsonld

browser

<script src="https://frogcat.github.io/ttl2jsonld/ttl2jsonld.js"></script>

Usage

node.js

You can write your own code.

const ttl2jsonld = require('@frogcat/ttl2jsonld').parse;

const ttl = `@prefix foaf: <http://xmlns.com/foaf/0.1/> .

<http://manu.sporny.org/about#manu> a foaf:Person;
  foaf:name "Manu Sporny";
  foaf:homepage <http://manu.sporny.org/> .
`;

const jsonld = ttl2jsonld(ttl);

console.log(JSON.stringify(jsonld,null,2));

Command line interface is also available.

$ npm install @frogcat/ttl2jsonld
$ ttl2jsonld {input_turtle} > {output_jsonld}
or
$ cat {input_turtle} | ttl2jsonld > {output_jsonld}

browser

This converter is exported to ttl2jsonld global object. Call ttl2jsonld.parse(ttl) to perform conversion.

<!-- include ttl2jsonld.js -->
<script src="https://frogcat.github.io/ttl2jsonld/ttl2jsonld.js"></script>

<!-- run script -->
<script>
const ttl = `@prefix foaf: <http://xmlns.com/foaf/0.1/> .

<http://manu.sporny.org/about#manu> a foaf:Person;
  foaf:name "Manu Sporny";
  foaf:homepage <http://manu.sporny.org/> .
`;

const jsonld = ttl2jsonld.parse(ttl);

console.log(JSON.stringify(jsonld,null,2));
</script>

API

Given turtle_string, ttl2jsonld.parse returns JSON Object.

var json_object = ttl2jsonld.parse(turtle_string);

When you want to pass baseIRI, give second argument like this.

var json_object = ttl2jsonld.parse(turtle_string, {
  baseIRI : "http://example.org/"
});

For developers

building

  • Build with PEG.js.
  • Main code is spec/ttl2jsonld.pegjs.
  • When you edit code, run npm run build to generate ttl2jsonld.js.

testing

版本与发布记录

@frogcat/ttl2jsonld 共发布 11 个版本,首次发布于 2019/06/03;过去 12 个月发布了 1 个版本。

版本发布日期距今
0.0.11latest2026/10/151 个月前
0.0.102025/01/151.8 年前
0.0.92023/01/263 年前
0.0.82022/03/244 年前
0.0.72022/02/174 年前
0.0.62020/07/176 年前

关于 @frogcat/ttl2jsonld 的常见问题

@frogcat/ttl2jsonld 是什么?

Turtle to JSON-LD converter for node.js and browser, no library dependencies

如何安装 @frogcat/ttl2jsonld?

在项目目录运行 npm install @frogcat/ttl2jsonld,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 ttl2jsonld,可以用 npx ttl2jsonld 直接运行。

@frogcat/ttl2jsonld 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/frogcat__ttl2jsonld 是否存在。

@frogcat/ttl2jsonld 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@frogcat/ttl2jsonld 可以商用吗?

@frogcat/ttl2jsonld 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@frogcat/ttl2jsonld 的下载量有多少?

根据 npm 官方下载统计,@frogcat/ttl2jsonld 在 2026/10/16 – 2026/11/14 这 30 天内被下载 80,769 次,日均约 2,692 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@frogcat/ttl2jsonld 还在维护吗?

最新版本 0.0.11 发布于 2026/10/15(1 个月前);至今共发布 11 个版本,其中过去 12 个月发布了 1 个;首次发布于 2019/06/03。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。