diff --git a/Excel-REST - Blank.xlsm b/Excel-REST - Blank.xlsm index 36ff4347..d7dc7d19 100644 Binary files a/Excel-REST - Blank.xlsm and b/Excel-REST - Blank.xlsm differ diff --git a/README.md b/README.md index d6a75365..17a4eb57 100644 --- a/README.md +++ b/README.md @@ -106,6 +106,7 @@ For more details, check out the [Wiki](https://github.com/timhall/Excel-REST/wik - Add RestClientBase for future use with extension for single-client applications - Add build scripts for import/export - New specs and bugfixes +- __v2.0.1__ Handle duplicate keys when parsing json #### v1.1.0 diff --git a/build/import.vbs b/build/import.vbs index 02c31f0d..d28f72c3 100644 --- a/build/import.vbs +++ b/build/import.vbs @@ -19,7 +19,7 @@ Else End If ' Include all standard Excel-REST modules -Modules = Array("RestHelpers.bas", "IAuthenticator.cls", "RestClient.cls", "RestRequest.cls", "RestResponse.cls") +Modules = Array("RestHelpers.bas", "IAuthenticator.cls", "RestClient.cls", "RestRequest.cls", "RestResponse.cls", "RestClientBase.bas") ' Open Excel KeepExcelOpen = OpenExcel(Excel) diff --git a/examples/Excel-REST - Example.xlsm b/examples/Excel-REST - Example.xlsm index c0fa7fd2..c30c3f70 100644 Binary files a/examples/Excel-REST - Example.xlsm and b/examples/Excel-REST - Example.xlsm differ diff --git a/specs/Excel-REST - Specs.xlsm b/specs/Excel-REST - Specs.xlsm index b4ccc203..9d8262bc 100644 Binary files a/specs/Excel-REST - Specs.xlsm and b/specs/Excel-REST - Specs.xlsm differ diff --git a/specs/RestHelpersSpecs.bas b/specs/RestHelpersSpecs.bas index 7cacb40f..27f2d50e 100644 --- a/specs/RestHelpersSpecs.bas +++ b/specs/RestHelpersSpecs.bas @@ -51,6 +51,16 @@ Public Function Specs() As SpecSuite End If End With + With Specs.It("should overwrite parsed json for duplicate keys") + json = "{""a"":1,""a"":2,""a"":3}" + Set Parsed = RestHelpers.ParseJSON(json) + + .Expect(Parsed).ToBeDefined + If Not Parsed Is Nothing Then + .Expect(Parsed("a")).ToEqual 3 + End If + End With + With Specs.It("should convert to json") Set Obj = CreateObject("Scripting.Dictionary") Obj.Add "a", 1 diff --git a/src/IAuthenticator.cls b/src/IAuthenticator.cls index 5f0155c3..a1593565 100644 --- a/src/IAuthenticator.cls +++ b/src/IAuthenticator.cls @@ -8,7 +8,7 @@ Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = True '' -' IAuthenticator v2.0.0 +' IAuthenticator v2.0.1 ' (c) Tim Hall - https://github.com/timhall/Excel-REST ' ' Interface for creating authenticators for rest client diff --git a/src/RestClient.cls b/src/RestClient.cls index 5b3ae0e4..12587924 100644 --- a/src/RestClient.cls +++ b/src/RestClient.cls @@ -8,7 +8,7 @@ Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = True '' -' RestClient v2.0.0 +' RestClient v2.0.1 ' (c) Tim Hall - https://github.com/timhall/Excel-REST ' ' Interact with REST web services from Excel @@ -19,7 +19,7 @@ Attribute VB_Exposed = True ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Option Explicit -Private Const UserAgent As String = "Excel Client v2.0.0 (https://github.com/timhall/Excel-REST)" +Private Const UserAgent As String = "Excel Client v2.0.1 (https://github.com/timhall/Excel-REST)" Private Const DefaultTimeoutMS As Integer = 5000 diff --git a/src/RestClientBase.bas b/src/RestClientBase.bas index cc9cb8a7..919a3edc 100644 --- a/src/RestClientBase.bas +++ b/src/RestClientBase.bas @@ -1,6 +1,6 @@ Attribute VB_Name = "RestClientBase" '' -' RestClientBase v2.0.0 +' RestClientBase v2.0.1 ' (c) Tim Hall - https://github.com/timhall/Excel-REST ' ' Extendable RestClientBase for developing custom client classes @@ -15,7 +15,7 @@ Attribute VB_Name = "RestClientBase" ' ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ' Option Explicit -Private Const UserAgent As String = "Excel Client v2.0.0 (https://github.com/timhall/Excel-REST)" +Private Const UserAgent As String = "Excel Client v2.0.1 (https://github.com/timhall/Excel-REST)" Private Const TimeoutMS As Integer = 5000 Private Initialized As Boolean diff --git a/src/RestHelpers.bas b/src/RestHelpers.bas index 53880e54..68953656 100644 --- a/src/RestHelpers.bas +++ b/src/RestHelpers.bas @@ -1,6 +1,6 @@ Attribute VB_Name = "RestHelpers" '' -' RestHelpers v2.0.0 +' RestHelpers v2.0.1 ' (c) Tim Hall - https://github.com/timhall/Excel-REST ' ' Common helpers RestClient @@ -398,6 +398,7 @@ End Function ' - Updated json_parseNumber to reduce chance of overflow ' - Swapped Mid for Mid$ ' - Handle colon in object key +' - Handle duplicate keys in object parsing ' - Change methods to Private and prefix with json_ ' ' ======================================================================================== ' @@ -442,8 +443,9 @@ Private Function json_parseObject(ByRef str As String, ByRef index As Long) As O If Mid$(str, index, 1) <> "{" Then Err.Raise vbObjectError + INVALID_OBJECT, Description:="char " & index & " : " & Mid$(str, index) index = index + 1 - Do + Dim Key As String + Do Call json_skipChar(str, index) If "}" = Mid$(str, index, 1) Then index = index + 1 @@ -453,11 +455,12 @@ Private Function json_parseObject(ByRef str As String, ByRef index As Long) As O Call json_skipChar(str, index) End If - Dim Key As String - - ' add key/value pair - json_parseObject.Add Key:=json_parseKey(str, index), Item:=json_parseValue(str, index) - + Key = json_parseKey(str, index) + If Not json_parseObject.Exists(Key) Then + json_parseObject.Add Key, json_parseValue(str, index) + Else + json_parseObject.Item(Key) = json_parseValue(str, index) + End If Loop End Function diff --git a/src/RestRequest.cls b/src/RestRequest.cls index 065e970e..a53250b9 100644 --- a/src/RestRequest.cls +++ b/src/RestRequest.cls @@ -8,7 +8,7 @@ Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = True '' -' RestRequest v2.0.0 +' RestRequest v2.0.1 ' (c) Tim Hall - https://github.com/timhall/Excel-REST ' ' Create a request for use with a rest client diff --git a/src/RestResponse.cls b/src/RestResponse.cls index 3439a9ea..d4939f34 100644 --- a/src/RestResponse.cls +++ b/src/RestResponse.cls @@ -8,7 +8,7 @@ Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = True '' -' RestResponse v2.0.0 +' RestResponse v2.0.1 ' (c) Tim Hall - https://github.com/timhall/Excel-REST ' ' Wrapper for http responses