Unexpected outcome working with SetP. Creates brand new data instead of hydrating existing path
Closed this issue · 3 comments
Hello @Jeffail
I am trying to give your library a solid go of mimicking C#'s Dynamic construct, and i'm frankly running in to a lot of issues trying to pair against your documentation. Admittedly this could be my assumptions, please consider the following JSON:
{
"Slices": [{
"Origin": "DCA",
"Destination": "SEA",
"IsRefundable": "False",
"DepartureDate": "",
"LoyaltyTier": "None",
"Segments": [{
"FareType": "coach",
"Origin": "DCA",
"Destination": "SEA",
"DepartureDateTime": "",
"CarrierFlightNumber": "XXXXX"
}]
}],
"Passengers": [{
"PassengerType": "ADT",
"PassengerCount": "1"
}]
}
With which i'm trying to manipulate with the following code snippet:
tomorrow := time.Now().Add(time.Hour * 24).Format("2006-01-02")
validatePricingObj, err := gabs.ParseJSONFile(pricingRequestPath) //this is data above
validatePricingObj.SetP(fmt.Sprintf("%s %s", tomorrow, "08:00"), "PriceResponse.Slices.0.DepartureTime")
validatePricingObj.SetP(fmt.Sprintf("%s %s", tomorrow, "10:30"), "PriceResponse.Slices.0.Segments.0.DepartureDateTime")
What I end up with is the following, brand new data path, instead of updating the data in the path I supplied.
{\"Passengers\":[{\"PassengerCount\":\"1\",\"PassengerType\":\"ADT\"}],\"PriceResponse\":{\"Slices\":{\"0\":{\"DepartureTime\":\"2020-09-24 08:00\",\"Segments\":{\"0\":{\"DepartureDateTime\":\"2020-09-24 10:30\"}}}}},\"Slices\":[{\"DepartureDate\":\"\",\"Destination\":\"SEA\",\"IsRefundable\":\"False\",\"LoyaltyTier\":\"None\",\"Origin\":\"DCA\",\"Segments\":[{\"CarrierFlightNumber\":\"XXXXX\",\"DepartureDateTime\":\"\",\"Destination\":\"SEA\",\"FareType\":\"coach\",\"Origin\":\"DCA\"}]}]}"}
Would appreciate your direct assistance, this is blocking our implementation of your package and i'd hate to have to look elsewhere as this seems very promising.
Thanks!!
Michael
Hey @n3rd253, are you definitely importing V2 of the api? The import path should be github.com/Jeffail/gabs/v2
. Your code looks fine but I'll double check it next time I'm at a PC.
import (
"bytes"
"errors"
"fmt"
"io/ioutil"
"net/http"
settingsLib "pnrhelperservice/internal/settings"
"pnrhelperservice/internal/utils"
"time"
"dev.azure.com/itsals/CustomerMobile/_git/lumberjack.git"
"github.com/Jeffail/gabs/v2"
"github.com/google/uuid"
)
This is the service itself, and here we have the module declaration itself
module helperservice
go 1.14
require (
dev.azure.com/itsals/CustomerMobile/_git/lumberjack.git v0.0.0-20200415161002-d076b9d4a593
github.com/Azure/azure-sdk-for-go v46.1.0+incompatible
github.com/Azure/go-autorest/autorest v0.11.4
github.com/Azure/go-autorest/autorest/azure/auth v0.5.1 // indirect
github.com/Azure/go-autorest/autorest/to v0.4.0 // indirect
github.com/Azure/go-autorest/autorest/validation v0.3.0 // indirect
github.com/Jeffail/gabs/v2 v2.6.0
github.com/fsnotify/fsnotify v1.4.9
github.com/go-xmlfmt/xmlfmt v0.0.0-20191208150333-d5b6f63a941b
github.com/google/uuid v1.1.2
github.com/gorilla/mux v1.7.4
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/spf13/viper v1.7.1
github.com/stretchr/testify v1.3.0
)
Sorry. I'm pretty sure I figured it out.
Invalid json pathing is invalid and new.