最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

porting - JavaScript implementation of jq? - Stack Overflow

programmeradmin0浏览0评论

The only implementation of jq seems to be in C. Is there anything comparable in (browser-side) JavaScript?

The reason I'm asking is basically to work out how much it's worth investing in jq - I generally prefer toolkits that JS-based, since they can be installed via NPM, can be used in the browser et. And those are two environments likely to encounter JSON...

The only implementation of jq seems to be in C. Is there anything comparable in (browser-side) JavaScript?

The reason I'm asking is basically to work out how much it's worth investing in jq - I generally prefer toolkits that JS-based, since they can be installed via NPM, can be used in the browser et. And those are two environments likely to encounter JSON...

Share Improve this question edited Apr 23, 2015 at 7:06 Steve Bennett asked Apr 23, 2015 at 6:58 Steve BennettSteve Bennett 126k45 gold badges185 silver badges240 bronze badges 3
  • just curious to know why do you need that ? may be you can use node.js for that its server side – NullPoiиteя Commented Apr 23, 2015 at 7:01
  • depends on what parts you want. js itself can do that stuff. might look into taffyDB, mustache, and underscore. – dandavis Commented Apr 23, 2015 at 7:02
  • good question, I've elaborated. – Steve Bennett Commented Apr 23, 2015 at 7:06
Add a comment  | 

7 Answers 7

Reset to default 9

There is fiatjaf/jq-web

This is a build of jq, the command-line JSON processor in Javascript using Emscripten along with a wrapper for making it usable as a library.

Demo here https://jq.alhur.es/jiq/

You may be interested in checking out JMESPath, a query language for JSON. It has implementations on many languages, including Javascript.

I implemented a jq parser, interpreter, and (basic) formatter in TypeScript:

@jq-tools/jq

So far, all of jq's syntax is supported (with the exception of the modules). And although a good portion of built-in filters and formats still needs to be implemented, a few are already there. Most of the functionality is properly tested (there are over a thousand test cases).

Here, I attach a basic usage example:

import { jq } from '@jq-tools/jq';

const transform = jq<number, number>`.[] | . * 2`;
Array.from(transform([1, 2, 3]));
// Output: [2, 4, 6]

I do not really have any solid benchmarks, but so far it seemed to be faster than jq-web (at least on small data).

jq.node looks pretty interesting and seems to be getting popular. Features include a mash of jq and javascript, claim is that "jq.node is JavaScript and Lodash in your shell" and "some features of jq are not currently implemented in jq.node". Not sure if it can be used in the browser. But it can be installed with npm:

https://github.com/fgribreau/jq.node

I implemented micro-jq specifically so I could evaluate JQ expressions in the browser. It implements a subset that should allow most basic uses for selecting fields.

You might also want to check out my take on this: https://github.com/kantord/emuto

I specifically implemented it to create a jq alternative that can be used in a browser. As an extra, it can also compile to JavaScript, so in some situation you might not even need to bundle in the compiler itself. (Although it's quite small anyway)

What about fx? It's a command-line JSON processing tool.

发布评论

评论列表(0)

  1. 暂无评论