Comments (5)
Hey @cptspartano, sorry for the delayed response...
For 1. it sounds like you're looking for something like Bloblang, which makes use of some Gabs functions under the hood. See for example how I used it here: benthosdev/benthos#1036. You can import it into your own project like so: https://pkg.go.dev/github.com/benthosdev/benthos/[email protected]/public/bloblang#example-package-BloblangRestrictedEnvironment
For 2. maybe you can make use of https://pkg.go.dev/github.com/Jeffail/gabs/v2#Container.Flatten or https://pkg.go.dev/github.com/Jeffail/gabs/v2#Container.FlattenIncludeEmpty, but I think you want to get the ancestor path all the way to the root when given a child element, which doesn't seem to fit into the Gabs model, because each element only stores information about its children... What are you trying to achieve? If you need to diff documents, maybe something like https://pkg.go.dev/github.com/r3labs/diff/v3 might be more appropriate.
from gabs.
Hi! Right now I have don't have any needs since the question was because of a project I was working in a company. Since the contract ended, so did my relation with that project.
Anyway, just in case someone comes with the same questions, the idea was, given two JSON, compare them field by field, with the caveat (I don't know if that's well said) that both of them were dynamically created, so one could have some fields that the other didn't. So what I was thinking was to iterate through one of the JSON, and with each field, extract it's path, and use it with gabs (Search function) on the other JSON and compare both fields to see if they were the same. I don't know if it is clear.
Anyway, I will have a look when I can to the options you gave, just for personal knowledge. Thanks a lot!
from gabs.
OK, when you say "dynamically created" do you mean that you already have a Go object instead of the actual JSON string? The efficient way to compare them would be to use something like https://pkg.go.dev/github.com/google/go-cmp/cmp#Equal or a similar package. There are many such packages out there so you don't have to roll your own, but yeah, you could if you wanted to. Otherwise, if you're starting with the JSON string, then definitely look into https://pkg.go.dev/github.com/r3labs/diff/v3 or https://pkg.go.dev/github.com/nsf/jsondiff or similar... Here's a collection of various JSON packages: https://github.com/avelino/awesome-go#json
from gabs.
Hi, sorry for the delay, I was on a trip and I wasn't paying attention to emails and all that.
I didn't know how to say it, so when I say "dynamically created" I'm saying that I'm not the one creating the JSON files by hand. Instead, they were being created outside the program (and sent to it), more or less in a random manner and, as I said, " one could have some fields that the other didn't". I don't know if that solves your question. Anyway, I don't think it's relevant for this thread, and I don't want to give you more headaches than necessary :D
from gabs.
Oh, OK. No worries! Since you're dealing with JSON strings, I suggested a few libraries above that I think will help you achieve your goal.
from gabs.
Related Issues (20)
- SetP has unexpected outcome with gabs.Container as value HOT 1
- Iterate over json root keys HOT 2
- Not getting value from key HOT 2
- Generate Array of Struct HOT 2
- add new json item not sync in memory HOT 2
- Selecting only inner fields HOT 1
- gabs.Container.Path() returns null, even the value exists HOT 2
- Container.Set does not take effect on parent node if param "hierarchy" is empty HOT 5
- Merge fails on "pure" arrays HOT 2
- Is there any way we can find the key in an object in a JSON file HOT 2
- Finding whether the keys of the input json is a subset of a array of string values. HOT 1
- How to create a JSON array HOT 3
- Path/Search does not work with arrays HOT 2
- How to create additional keys and arrays HOT 1
- how to Preserving key order by json parse ? HOT 1
- to byte[] diff error? HOT 4
- Lists not working? HOT 1
- Feature request: use -1 index to get last item in array.
- K8s `unstructured` helper? HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from gabs.