GithubHelp home page GithubHelp logo

json-pointer's Introduction

Build Status codecov license

JavaScript Object Notation (JSON) Pointer

This is implementation of rfc6901.

JsonPointer for Json, like XPath for XML, used to locate part of document using format string.

library functionality:

  • JsonPointer path parsing and verification
  • element search in a document
  • JsonPointer path component encoding

Json document format accepted: JSONValue

Interface

    struct JsonPointer
    {
    
    	/** 
    	 * Constructor. 
    	 * @throws Exception if error in path
    	 */
    	@safe this(string path);

       /// encode path component, quoting '~' and '/' symbols according to rfc6901
    	@safe static encodeComponent(string component) pure;
    	
    	// find element in given document according to path
    	Nullable!JSONValue evaluate(JSONValue root);
    	
    }

Usage examples

    import vision.json.pointer;
    import std.json;
    
    string s = `{ "language": "D", "rating": 3.5, "code": "42", "o": {"p1": 5, "p2": 6}, "a": [1,2,3,4,5] }`;
    JSONValue j = parseJSON(s);

    // tests for successful requests
    assert(JsonPointer("/language").evaluate(j).str == "D");
    assert(JsonPointer("/rating").evaluate(j).floating == 3.5);
    assert(JsonPointer("/o/p1").evaluate(j).integer == 5);
    assert(JsonPointer("/a/3").evaluate(j).integer == 4);
    
    // test encodeComponent
    assert(JsonPointer.encodeComponent("a/b~c") == "a~1b~0c");
    

json-pointer's People

Contributors

crimaniak avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

json-pointer's Issues

GDC build failed

src/vision/json/pointer.d:5:12: error: module std.typecons import 'nullable' not found, did you mean struct 'Nullable(T)'?
import std.typecons : Nullable, nullable;
^
gdc failed with exit code 1.

LDC build failed

src/vision/json/pointer.d(17,16): Error: module std.algorithm import 'substitute' not found

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.