Skip to content
This repository


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Kick-ass JSON utilities for JavaScript and CoffeeScript

branch: master

Fetching latest commit…


Cannot retrieve the latest commit at this time

Octocat-spinner-32 lib
Octocat-spinner-32 src
Octocat-spinner-32 test
Octocat-spinner-32 .gitignore Adding Cakefile and first build of jason-fu
Octocat-spinner-32 .npmignore Initial commit of json-fu
Octocat-spinner-32 Cakefile Tagging the release as 0.2.1
Octocat-spinner-32 LICENSE
Octocat-spinner-32 Fixing readme typos
Octocat-spinner-32 package.json
       _______ ____  _   __      ______     
      / / ___// __ \/ | / /     / ____/_  __
 __  / /\__ \/ / / /  |/ /_____/ /_  / / / /
/ /_/ /___/ / /_/ / /|  /_____/ __/ / /_/ / 
\____//____/\____/_/ |_/     /_/    \__,_/  

npm install json-fu


JSON-Fu aims to be a collection of kick-ass JSON utilities for JavaScript and CoffeeScript. Right now,
it supports the following features:

  • Drop-in replacement for JSON.parse and JSON.stringify
  • stringify supports the depth parameter just like node's util.inspect
  • Fancy serialization and deserialization support with serialize() and deserialize()
  • Simple XPath-like query syntax (jPath) for object models


Unlike simple JSON stringification, JSON-Fu's serialization functionality understands references inside the object.
It even handles circular references!


Let's say you want to send a shallow version of a deeper object across the wire. Wouldn't it be nice if the other side
not only knew that there was a deeper version available, but how many subobjects there were at the next level?


project = {
    name: "My Project",
    client: "A client",
    tasks: [

If this were sent accross the wire using:

jsonfu.serialize(project, 1)

The other end would receive it as:

project = {
    name: "My Project",
    client: "A client",
    tasks: "__@JSON_more(4)"

The "__@JSON_more(4)" part is called a sigil, and it is one of several special values
that the serializer can emit. (Note: stringify makes sure to maintain compatibility with standard JSON, so you must use serialize() to take advantage of these.)

In this case, client code could detect the presence of the more sigil and not only know that it could get more information about tasks, but put the number of tasks it would get (4) on the UI. This kind of thing usually requires custom code, but it's built in
to JSON-Fu!

XPath-like querying with jPath

JSON-Fu has a simple method called "selectObject" that takes a root object and a "jPath"
query string. It then returns the object matching that string (or undefined if not found).


object = "test";
jsonfu.selectObject(object, "/") === "test"

object = [1,2,3];
jsonfu.selectObject(object, "/2") === 3

object = [1, 2, "foo": {bar: "baz"}];
jsonfu.selectObject(object, "/foo/bar") === "baz"
JSON-Fu is Copyright (c) 2011 by GreatFoundry Software, Inc.
It is free software under the MIT license
Something went wrong with that request. Please try again.