Skip to content

Commit

Permalink
Merge pull request #9 from YongHee-Kim/develop
Browse files Browse the repository at this point in the history
Merge minor fixes
  • Loading branch information
YongHee-Kim authored Jun 25, 2024
2 parents 17e4d97 + 24d540d commit 654ddf6
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 6 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2020 Devsisters Corp.
Copyright (c) 2022 Yonghee Kim

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "JSONPointer"
uuid = "cc3ff66e-924d-4e6b-b111-1d9960e4bba9"
authors = ["김용희 <yongheekim@devsisters.com>"]
authors = ["김용희 <masterplanf@gmail.com>"]
version = "0.5.0"

[deps]
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,17 @@

Implementation of JSON Pointers according to [RFC 6901](https://www.rfc-editor.org/rfc/rfc6901)

## Overview
# Overview
[JSONPointer](https://tools.ietf.org/html/rfc6901/) is a Unicode string containing a sequence of zero or more reference tokens, each prefixed by a '/' (%x2F) character.

## Key Features
- JSONPointer Syntax Support: The package supports the creation and manipulation of JSON Pointers, allowing users to navigate and access elements within JSON data structures.

**Exported Functions and Types:**
- `@j_str`: allowing string literal `j"/foo"` to construct a JSONPointer
- `PointerDict`: A type that extends AbstractDict to support JSON Pointers.
- `has_pointer`, `get_pointer`, `set_pointer!`: Functions to check if a pointer exists, retrieve a value by pointer, and set a value by pointer, respectively.

# Tutorial

## Installation
Expand Down
2 changes: 1 addition & 1 deletion src/JSONPointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ using OrderedCollections, TypedDelegation

include("pointer.jl")
include("pointerdict.jl")
include("dict_interface.jl")
include("abstractdict_interface.jl")

export @j_str, PointerDict, has_pointer, get_pointer, set_pointer!

Expand Down
File renamed without changes.
3 changes: 1 addition & 2 deletions src/pointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,6 @@ Base.:(==)(a::Pointer{U}, b::Pointer{U}) where {U} = a.tokens == b.tokens
# ==============================================================================

_checked_get(collection::AbstractArray, token::Int) = collection[token]

_checked_get(collection::AbstractDict, token::String) = get_pointer(collection, token)

function _checked_get(collection, token)
Expand Down Expand Up @@ -242,7 +241,7 @@ _convert_v(v::U, ::Pointer{U}) where {U} = v
function _convert_v(v::V, p::Pointer{U}) where {U, V}
v = ismissing(v) ? _null_value(p) : v
try
#Conversion to OrderedDict is deprecated for unordered associative containers. Need to be sorted before the conversion
# Conversion to OrderedDict is deprecated for unordered associative containers. Have to be sorted before the conversion
if eltype(p) <: OrderedDict
if <:(V, OrderedDict) == false
return convert(eltype(p), sort!(OrderedDict(v)))
Expand Down
12 changes: 12 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,16 @@ end
@test eltype(p2) == Missing
@test ismissing(JSONPointer._null_value(p2))


pointer_doc = PointerDict(Dict(:a => 1))
@test isa(pointer_doc, PointerDict)
@test isa(PointerDict(pointer_doc), PointerDict)

@test JSONPointer.dicttype(pointer_doc) == PointerDict

doc = Dict("a" => 1)
set_pointer!(doc, "b", 2)
@test get_pointer(doc, "a", 0) == 1
@test get_pointer(doc, "b", 0) == 2
@test ismissing(get_pointer(doc, "c", missing))
end

0 comments on commit 654ddf6

Please sign in to comment.