How to import JSON file using PHP script

Hi all,
I have a json file with content:

[
    {
        "ProcessId":  448,
        "ProcessName":  "wininit.exe",
        "Path":  "C:\\Windows\\system32\\wininit.exe",
        "CommandLine":  "wininit.exe"
    },
    {
        "ProcessId":  456,
        "ProcessName":  "winlogon.exe",
        "Path":  "C:\\Windows\\system32\\winlogon.exe",
        "CommandLine":  "winlogon.exe"
    },
    {
        "ProcessId":  524,
        "ProcessName":  "lsass.exe",
        "Path":  "C:\\Windows\\system32\\lsass.exe",
        "CommandLine":  "C:\\Windows\\system32\\lsass.exe"
    },
    {
        "ProcessId":  656,
        "ProcessName":  "svchost.exe",
        "Path":  "C:\\Windows\\system32\\svchost.exe",
        "CommandLine":  "C:\\Windows\\system32\\svchost.exe -k DcomLaunch"
    },
    {
        "ProcessId":  700,
        "ProcessName":  "svchost.exe",
        "Path":  "C:\\Windows\\system32\\svchost.exe",
        "CommandLine":  "C:\\Windows\\system32\\svchost.exe -k RPCSS"
    }
]

How can I import it into MongoDB?

Given the JSON schema you shared, I expect you can utilize PHP’s json_decode() method to parse the JSON as an array (sequential list) of associative arrays, and then use a method like Collection::insertMany() to insert the entire batch at once. Note that this will result in each document being assigned a new ObjectId for its _id field, so if you prefer to rely on the ProcessId instead you’ll need to manually rename that field to _id before passing the documents along to the insert method. That said, there’s no harm in keeping your document as-is and allowing MongoDB to generate its own ObjectId.

Note that the PHP driver does have additional functions for parsing JSON, but those are mainly useful if you’re reading Extended JSON, which is a specific format of JSON with syntax for expressing BSON types beyond the basic types supported by common JSON. I don’t think this applies to your use case, but it bears mentioning.