Comments (6)
The jm script (https://github.com/pkoppstein/jm) is based on JSON Machine, and could be used as follows to find the value of a specific key:
$ jm -s | grep --max-count 1 '^{"PTHT0000001"'
Even if you don't want to use jm itself, you could examine it to see how it accomplishes what you want.
Alternatively, you might consider using the --stream option of jq (https://github.com/stedolan/jq), which is designed for just this kind of problem:
$ jq -n --stream 'first(fromstream( (inputs | select(.[0][0] == "PTHT0000001")), [["PTHT0000001"]] ))'
from json-machine.
If you need to use it from inside PHP, just use simple foreach
and find your key there.
foreach (Items::fromFile('500gb.json') as $key => $item) {
if ($key === "PTHT0012803") {
// your code
}
}
Keep in mind, that a file of this size might get hours to parse with JSON Machine. I guess 2-4 depending on the machine and PHP configuration. You also might be interested in #97.
from json-machine.
Sorry, I read 500 GB instead of just 5 GB. Then it should be a matter of minutes. Make sure xdebug is disabled and JIT enabled.
Also make longer your php time limit if you parse from browser.
from json-machine.
The jm script (https://github.com/pkoppstein/jm) is based on JSON Machine, and could be used as follows to find the value of a specific key:
$ jm -s | grep --max-count 1 '^{"PTHT0000001"'
Even if you don't want to use jm itself, you could examine it to see how it accomplishes what you want.
Alternatively, you might consider using the --stream option of jq (https://github.com/stedolan/jq), which is designed for just this kind of problem:
$ jq -n --stream 'first(fromstream( (inputs | select(.[0][0] == "PTHT0000001")), [["PTHT0000001"]] ))'
Thank you for your help! I will try the method you mentioned later.
from json-machine.
If you need to use it from inside PHP, just use simple
foreach
and find your key there.foreach (Items::fromFile('500gb.json') as $key => $item) { if ($key === "PTHT0012803") { // your code } }
Keep in mind, that a file of this size might get hours to parse with JSON Machine. I guess 2-4 depending on the machine and PHP configuration. You also might be interested in #97.
Thank you for your reply. I used code like this before, but it took too long. I think it may be because foreach takes too much time. Is there any way to avoid this situation in jsonmachine? If not, I will try to split large files.
from json-machine.
If you split them, it will take about the same time anyway. There is no faster solution in JSON Machine for now. Keep up with #97 which should bring some speedup.
from json-machine.
Related Issues (20)
- Why only red is output HOT 4
- Iterating items from specific position HOT 1
- Document-dependent path evaluation HOT 11
- Problem With `getCurrentJsonPointer()` HOT 4
- Non-Intersecting Pointers Considered Intersecting HOT 2
- Unicode Escape Sequences Support HOT 4
- Wrong key when combining list and scalar value pointers
- GeoJSON properties only
- Thank you for this awesome library. HOT 3
- Deprecated warning HOT 2
- Getting un catchable errors on non JSON files HOT 9
- Option or method for preserving the precision of numeric literals HOT 6
- CLI script for streaming HOT 8
- passing headers HOT 1
- UnexpectedEndSyntaxErrorException HOT 19
- taking time while parsing HOT 8
- Basic Usage Using PHP and Brew HOT 7
- Parsing nested values in objects HOT 4
- Unexpected symbol with Items::fromStream HOT 2
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 json-machine.