json-pointer 0.0.1

IETF RFC 6901 implementation: JavaScript Object Notation (JSON) Pointer


To use this package, run the following command in your project's root directory:

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");
    
Authors:
  • Alexey Kulentsov
Dependencies:
none
Versions:
0.0.3 2018-Jun-02
0.0.2 2018-Apr-25
0.0.1 2018-Apr-25
~master 2018-Jun-02
Show all 4 versions
Download Stats:
  • 0 downloads today

  • 0 downloads this week

  • 0 downloads this month

  • 70 downloads total

Score:
0.5
Short URL:
json-pointer.dub.pm