Comments (3)
Hi! No, you will have to iterate till needed index, and then return early. But overall performance wise it will be the same.
from jsonparser.
you will have to iterate till needed index, and then return early
How do you return early though? Same for ArrayEach
, how do I just get the first element without having ArrayEach
invoke the callback for each element of the array? There is no way to stop it.
from jsonparser.
you will have to iterate till needed index, and then return early
How do you return early though? Same for
ArrayEach
, how do I just get the first element without havingArrayEach
invoke the callback for each element of the array? There is no way to stop it.
I just realized that this works too and solves my problem ๐
var jsonData = []byte(`{
"hello":[{},{}, "{fake-object}" ],
"batch" : [
{
"userId": 123,
"context": {"library":{
"name":"analytics-go",
"version": "1.2.3"
}}
},
{ },
{},
{"inner" : { } }
]
}`)
func TestVersionFromEvent(t *testing.T) {
value, dataType, _, err := jsonparser.Get(jsonData, "batch", "[0]", "context", "library", "version")
require.NoError(t, err)
require.Equal(t, jsonparser.String, dataType)
require.Equal(t, "1.2.3", string(value))
}
from jsonparser.
Related Issues (20)
- How to break in ArrayEach ?
- Continuing iteration in ArrayEach() HOT 1
- The set function does not work
- package github.com/buger/jsonparser is not a main package HOT 3
- Get call panics on empty json array or invalid json with an empty path - expecting an error to be returned
- [Proposal] New function based on EachKey
- Iterator support for Arrays & Objects
- Dead / Faulty code in ArrayEach? HOT 2
- The maximum number of byte files that ArrayEach supports
- Security - CVE-2020-10675 HOT 5
- Are there plans to release a new version๏ผ
- I don`t why it is not work
- how can i get length of array attribute
- ArrayEach correct behaviour
- Delete func data cannot has blank character
- Why were the patch versions for CVE-2020-10675 released so late?
- Set with index overrides always first position of the array
- Set() doesnt return a normal json data
- Add Native Support for Retrieving uint64
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 jsonparser.