odogono / elixir-jsonpointer Goto Github PK
View Code? Open in Web Editor NEWImplementation of RFC 6901 JavaScript Object Notation Pointer strings in Elixir
License: MIT License
Implementation of RFC 6901 JavaScript Object Notation Pointer strings in Elixir
License: MIT License
The following code
data = Jason.decode!(~s({"one":1,"two":2,"array":[1,2,3], "dict":{"four": "4", "five": "5"}}))
JSONPointer.get( data, "/array/0/1" )
returns:
** (FunctionClauseError) no function clause matching in JSONPointer.walk_container/7
Can it be updated to return an error tuple? something like:
{:error, "no function clause matching"}
nice library btw
According to the spec /c%d
should be a valid query string. See the following IEx session for details.
Erlang/OTP 21 [erts-10.0.7] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] [hipe]
Interactive Elixir (1.7.4) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> doc = ~S"""
...(1)> {
...(1)> "foo": ["bar", "baz"],
...(1)> "": 0,
...(1)> "a/b": 1,
...(1)> "c%d": 2,
...(1)> "e^f": 3,
...(1)> "g|h": 4,
...(1)> "i\\j": 5,
...(1)> "k\"l": 6,
...(1)> " ": 7,
...(1)> "m~n": 8
...(1)> }
...(1)> """
" {\n \"foo\": [\"bar\", \"baz\"],\n \"\": 0,\n \"a/b\": 1,\n \"c%d\": 2,\n \"e^f\": 3,\n \"g|h\": 4,\n \"i\\\\j\": 5,\n \"k\\\"l\": 6,\n \" \": 7,\n \"m~n\": 8\n }\n"
iex(2)> map = Jason.decode!(doc)
%{
"" => 0,
" " => 7,
"a/b" => 1,
"c%d" => 2,
"e^f" => 3,
"foo" => ["bar", "baz"],
"g|h" => 4,
"i\\j" => 5,
"k\"l" => 6,
"m~n" => 8
}
iex(3)> JSONPointer.get(map, "/c%d")
** (ArgumentError) malformed URI "c%d"
(elixir) lib/uri.ex:334: URI.decode/1
(elixir) lib/enum.ex:1314: Enum."-map/2-lists^map/1-0-"/2
(odgn_json_pointer) lib/json_pointer.ex:859: JSONPointer.parse/1
(odgn_json_pointer) lib/json_pointer.ex:441: JSONPointer.walk_container/4
(odgn_json_pointer) lib/json_pointer.ex:72: JSONPointer.get/2
https://tools.ietf.org/html/draft-handrews-relative-json-pointer-01
...once i determine what problem this solves
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.